#include #include #include using namespace std; struct studentRecord{ // Structu
ID: 3527281 • Letter: #
Question
#include #include #include using namespace std; struct studentRecord{ // Structure containing variables for all the double quiz1; // tests/quizes, including the letter grade double quiz2; double midterm; double final; double average; char grade; }; double getGrade(string, int); //Function prototype for the numerical grade char getLetter(double); //Function prototype for the letter grade studentRecord getScores(studentRecord); studentRecord updateAvgAndScore(studentRecord); studentRecord outputStudentRecord(studentRecord); int main() { studentRecord score; // Initialization of the structure & variable score getScores(score); updateAvgAndScore(score); outputStudentRecord(score); return 0; } studentRecord getScores(studentRecord score) { cout << "Enter the grades:" << endl; score.quiz1=getGrade("Quiz 1", 10); //Takes "Quiz 1" & a maximum value of 10 (points) and inputs it into the getGrade function and assigns it to score score.quiz2=getGrade("Quiz 2", 10); //Takes "Quiz 2" & a maximum value of 10 (points) and inputs it into the getGrade function and assigns it to score score.midterm=getGrade("Midterm", 100); //Takes "Midterm" & a maximum value of 100 (points) and inputs it into the getGrade function and assigns it to score score.final=getGrade("Final", 100); //Takes "Final" & a maximum value of 100 (points) and inputs it into the getGrade function and assigns it to score return score; } studentRecord updateAvgAndScore(studentRecord score) { score.average=(score.quiz1 + score.quiz2)/20.*100.*.25+score.midterm*.25+score.final*.5; //Calculates the class average based on percentages score.grade=getLetter(score.average); //Assigns a letter grade to the calculated class average return score; } studentRecord outputStudentRecord(studentRecord score) { cout << " Student Summary "; cout << "Quiz 1:" << score.quiz1 << endl; //Outputs the Quiz 1 score cout << "Quiz 2:" << score.quiz2 << endl; //Outputs the Quiz 2 score cout << "Midterm:" << score.midterm << endl; //Outputs the Midterm score cout << "Final:" << score.final << endl; //Outputs the Final score cout << "Semester average: " << score.average << endl; //Outputs the class average cout << "Final grade: " << score.grade << endl; //Outputs the letter grade return score; } double getGrade(string blank, int max) //Function header for the getGrade function which takes in the grade that the student received on said test/quiz { int scoreDef; cout << "Enter grade for " << blank << ": "; cin >> scoreDef; while (scoreDef<0||scoreDef>max) //While loop that tells user their score is out of the limit of 0 to 10, inclusive { cout << "Grade must be between 0 and "<<max<<" "; cout << "Enter grade for " << blank <<": "; cin >> scoreDef; } return scoreDef; } char getLetter(double sum)//Function header for the getLetter function which assigns a letter grade to the student's numerical average { char letter; if (sum>=90) //If else statements that assign letter grades based on average letter = 'A'; else if (sum>=80) letter = 'B'; else if (sum>=70) letter = 'C'; else if (sum>=60) letter = 'D'; else letter = 'F'; return letter; } Every time I compile the program I receive an uninitialized local variable error: why?Explanation / Answer
www.serkey.com/tag/namespace-maintain-student-scores My Training Period: xx hours From this Module you can jump to the Object Oriented idea and C++ or proceed to extra C Modules or Microsoft C: implementation specific to experience how C is used in the real implementation. The struct lab worksheets are: C/C++ struct part 1 and C/C++ struct part 2. Also the combination of the struct, arrays, pointers and function C worksheet 1, C lab worksheet part 2 and C lab worksheet part 3. The C & C++ programming skills that must be acquired: Able to understand and use structure (struct). Able to relate structure, functions and array. Able to understand and use typedef. Able to understand and use union. Able to understand and use enumeration (enum). 11.1 Structure (struct) We have learned that by using an array, we only can declare one data type per array, and it is same for other data types. To use the same data type with different name, we need another declaration. struct data type overcomes this problem by declaring aggregate data types. A structure is a collection of related data items stored in one place and can be referenced by more than one names. Usually these data items are different basic data types. Therefore, the number of bytes required to store them may also vary. It is very useful construct used in data structure, although in C++, many struct constructs has been replaced by class construct but you will find it a common in the Win32 programming's APIs. In order to use a structure, we must first declare a structure template. The variables in a structure are called elements or members. For example, to store and process a student’s record with the elements id_num (identification number), name, gender and age, we can declare the following structure. struct student { char id_num[5]; char name[10]; char gender; int age; }; Here, struct is a keyword that tells the compiler that a structure template is being declared and student is a tag that identifies its data structure. Tag is not a variable; it is a label for the structure’s template. Note that there is a semicolon after the closing curly brace. A structure tags simply a label for the structure’s template but you name the structure tag using the same rules for naming variables. The template for the structure can be illustrated as follow (note the different data size): Compiler will not reserve memory for a structure until you declare a structure variable same as you would declare normal variables such as int or float. Declaring structure variables can be done in any of the following ways (by referring to the previous example):
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.