Question
// T3DebugProg -- Simple Class Grade Structure Program to debug for Test 3 (Old Book) // // Program purpose: // 1) Program reads each student's
// T3DebugProg -- Simple Class Grade Structure Program to debug for Test 3 (Old Book) // // Program purpose: // 1) Program reads each student's names followed by their test score from // a text file "T3DebugData.txt" // 2) Program should output each student's name followed by test scores // and relevant grade to a file. // 3) Program should also find and print the highest test score and the // names of all the students that got that score. // 4) Program output file name is "T3DebugOut.txt". // 5) The program must also include struct for the students name and tests // 6) Assume 20 students max. // #include #include #include using namespace std; const int NO_OR_STUDENTS = 20; struct studentType { string studentFName; string studentLName; int testScore; char grade; } void getData(ifstream& inFile, studentType sList[], int listSize); void calculateGrade(studentType sList[], int listSize); void printResult(ofstream& outFile, const studentType sList[], int listSize); void holdscreen( string exitMessage ); int main() { ifstream inData; ofstream outData; studentType studentList[NO_OR_STUDENTS]; cout << " This program gets student names and test scores from one file " << "and writes a report to another file. "; inData.open("T3DbeugData.txt"); if (!inData) { cout << "The input file does not exist. Program terminates!" << endl; holdscreen ("Error Exit - Input file error!"); return 1; } outData.open("T3DebugOut.txt"); if (!outData) { cout << "Cannot open the output file. Program terminates!" << endl; holdscreen ("Error Exit - Output file error!"); return 1; } getData(inData, studentList, NO_OR_STUDENTS); calculateGrade(studentList, NO_OR_STUDENTS); printResult(outData, studentList, NO_OR_STUDENTS); holdscreen ("All the scores have been processed!"); return 0; } void getData(ifstream& inFile, studentType sList[], int listSize) { for (int i = 0; i < listSize; i++) inFile >> sList[i].studentFName >> sList[i].studentLName >> sList[i].testScore; return; } void calculateGrade(studentType sList[], int listSize) { for (int i = 0; i < listSize; i++) { switch (sList[i].testScore / 10) { case 10: case 9: sList[i].grade = 'A'; break; case 8: sList[i].grade = 'B'; break; case 7: sList[i].grade = 'C'; break; case 6: sList[i].grade = 'D'; break; case 5: case 4: case 3: case 2: case 1: case 0: sList[i].grade = 'F'; } } return; } int highestScore(const studentType sList[], int listSize) { int hScore = sList[0].testScore; for (int i = 1; i < listSize; i++) if (hScore < sList[i].testScore) hScore = sList[i].testScore; return hScore; } void printResult(ofstream& outFile, const studentType sList[]) { int maxScore = highestScore(sList, listSize); int i; outFile << setw(15) << "Student Name " << setw(10) << "Test Score" << setw(7) << "Grade" << endl; for (i = 0; i < listSize; i++) outfile << left << setw(25) << sList[i].studentLName + ", " + sList[i].studentFName << right << " " << setw(5) << sList[i].testScore << setw(6) << " " << sList[i].grade << endl; outFile << endl << "Highest Test Score: " << maxScore << endl; outFile << "Students having the highest test score:" << endl; for (i = 0; i < listSize; i++) if (sList[i].testScore == maxScore) outFile << sList[i].studentLName + ", " + sList[i].studentFName << endl; return; } void holdscreen( string exitMessage ) { char holdscr = 0; cout << " \t * * * " << exitMessage << " * * *" << " \t Enter a character and return to exit the program! "; cin >> holdscr; return; }
Directions:
Debug, (find the errors and correct them in), the program, T3DebugProg.cpp
Note:
The file and associated data file is attached with this part of the test download it.
Note that there are 6 errors.
Each error you find is worth 2 points for 12 points total.
The program should run when you have found and corrected all the errors.
Attach your updated source and output file when you get it working.
Short Essay Questions (worth 16 points):
With the advent of object-oriented programming, is it ever necessary to use C-type structs rather than classes? If so, when? What are the advantages or disadvantages of each approach? (5 points) (Think about how the object-oriented concept of reusability relates to structs, structs within arrays, arrays within structs, and structs within structs. Think of some applications in which defining these data types for later use would be beneficial) (3 points) . (8 points Total)
Discuss the relevant issues when determining whether to use public, protected or private members when defining new classes, especially base classes. (5 points) Are there any risks involved with using the protected member access specifier instead of the private member access specifier?. 3 points) . (8 points Total)
Modify the program (worth 20 points):
Modify the Chapter 10 Programming Example Abstract Creature program to add the following:
Add three more characters: Human, Elf and Dwarf
Expand Orc to 3 Types of Orcs: Minion, Warrior, and Boss
Expand the Main to include a menu to greet all the 3 alternate characters and the 3 different types of Orcs.
Required for program grade:
Source Code (complete)
Screenshot of running program.
Note partial credit will be given for incomplete programs that show progress from the original program.
Debug Data txt.:
Duckey Donald 85 Goof Goofy 89 Brave Balto 93 Snow Smitn 93 Alice Wonderful 89 Samina Akthar 85 Simba Green 95 Donald Egger 90 Brown Deer 86 Johny Jackson 95 Greg Gupta 75 Samuel Happy 80 Danny Arora 80 Sleepy June 70 Amy Cheng 83 Shelly Malik 95 Chelsea Tomek 95 Angela Clodfelter 95 Allison Nields 95 Lance Norman 88
abstract_creature.cpp:
//Abstract Creature //Demonstrates abstract classes #includeusing namespace std; class Creature //abstract class { public: Creature(int health = 100); virtual void Greet() const = 0; //pure virtual member function virtual void DisplayHealth() const; protected: int m_Health; }; Creature::Creature(int health): m_Health(health) {} void Creature::DisplayHealth() const { cout << "Health: " << m_Health << endl; } class Orc : public Creature { public: Orc(int health = 120); virtual void Greet() const; }; Orc::Orc(int health): Creature(health) {} void Orc::Greet() const { cout << "The orc grunts hello. "; } int main() { Creature* pCreature = new Orc(); pCreature->Greet(); pCreature->DisplayHealth(); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started