/ Published in: C++
grader program. input first name, last name, three test scores, and it creates an average and puts all of the info in a separate file named "students.txt"
Expand |
Embed | Plain Text
#include <cstdlib> #include <iostream> #include <fstream> #include <string> using namespace std; void gradeInput() { char grade; int f; float percent, testScore[3]; string fname, lname, infoArray[4]; cout << "\nplease enter in students' first name\n" << endl; cin >> fname; cout << "\nplease enter the students last name.\n" << endl; cin >> lname; ofstream inFile; inFile.open("students.txt", ios::app); cout << "\nplease enter in the test scores.\n" << endl; cin >> testScore[1]; cin >> testScore[2]; cin >> testScore[3]; float myScore = testScore[1]+testScore[2]+testScore[3]; percent = myScore/3; if (percent => 90) { grade = 'A'; } else if (percent > 80 && percent < 90) { grade = 'B'; } else if (percent > 70 && percent < 80) { grade = 'C'; } else if (percent > 55 && percent < 70) { grade = 'D'; } else if (percent <= 54) { grade = 'F'; } inFile << lname <<", "<< fname << " - " << grade <<" /"<< percent << "% " << endl; inFile.close(); } void printGrades() { system("cls"); string student; ifstream outFile ("students.txt"); while (outFile.good()) { getline (outFile, student); cout << student << endl; } outFile.close(); } void clear() { system("cls"); ofstream myClear; myClear.open("students.txt"); myClear << "" << endl; myClear.close(); } int main() { int i = 5; string command; cout << "would you like to input or read student grades and information?" << endl; do{ cin >> command; if (command == "input") { gradeInput(); } else if (command == "read") { printGrades(); } else if (command == "cleargrades") { clear(); } }while(i==5); } // output example: Harris, John - A / 95%
You need to login to post a comment.
