/* PROGRAM output formatting samples AUTHOR: FSU ID: COURSE INFORMATION: COP 3014 Recitation Number: 2 SUMMARY Print out a table with required outpput formats. INPUT N/A OUTPUT A table with required outpput formats. DATA STRUCTURES N/A ASSUMPTIONS N/A */ #include #include #include using namespace std; int main() { /************* Variable declaration *************/ const char BLANK = ' '; // storage for a blank space string stud_name_1 = "Alice", // storage for the name of the first student stud_name_2 = "Bob", // storage for the name of the second student stud_name_3 = "Cherry"; // storage for the name of the third student double proj1_score_1 = 100, // storage for the score of the first student in project 1 proj1_score_2 = 75.5, // storage for the score of the second student in project 1 proj1_score_3 = 72.5, // storage for the score of the third student in project 1 proj2_score_1 = 89, // storage for the score of the first student in project 2 proj2_score_2 = 79, // storage for the score of the second student in project 2 proj2_score_3 = 69; // storage for the score of the third student in project 2 double proj_average_score_1, // storage for the average score of the first student proj_average_score_2, // storage for the average score of the second student proj_average_score_3, // storage for the average score of the third student proj1_average_score, // storage for the average score of project 1 proj2_average_score, // storage for the average score of project 2 proj_average_score; // storage for the average score of all the projects char gpa_1, // storage for the GPA of the first student gpa_2, // storage for the GPA of the second student gpa_3; // storage for the GPA of the third student /************* Algorithm *************/ // calculate the average score of the each student proj_average_score_1 = (proj1_score_1 + proj2_score_1)/2; proj_average_score_2 = (proj1_score_2 + proj2_score_2)/2; proj_average_score_3 = (proj1_score_3 + proj2_score_3)/2; // calculate the average score of each project proj1_average_score = (proj1_score_1 + proj1_score_2 + proj1_score_3)/3; proj2_average_score = (proj2_score_1 + proj2_score_2 + proj2_score_3)/3; // calculate the average score of all the projects proj_average_score = (proj_average_score_1 + proj_average_score_2 + proj_average_score_3)/3; // calculate the GPA if (proj_average_score_1 > 90) gpa_1 = 'A'; else if (proj_average_score_1 > 80) gpa_1 = 'B'; else if (proj_average_score_1 > 80) gpa_1 = 'C'; else gpa_1 = 'D'; if (proj_average_score_2 > 90) gpa_2 = 'A'; else if (proj_average_score_2 > 80) gpa_2 = 'B'; else if (proj_average_score_2 > 80) gpa_2 = 'C'; else gpa_2 = 'D'; if (proj_average_score_3 > 90) gpa_3 = 'A'; else if (proj_average_score_3 > 80) gpa_3 = 'B'; else if (proj_average_score_3 > 80) gpa_3 = 'C'; else gpa_3 = 'D'; /************* Output *************/ cout << "==================================================" << endl; cout << '|' << setw(48) << BLANK << '|' << endl; cout << '|' << setw(18) << BLANK << "Grade Report" << setw(18) << BLANK << '|' << endl; cout << '|' << setw(48) << BLANK << '|' << endl; cout << "==================================================" << endl; /*************************************************************************************************/ /******************************** Modify below this line *****************************************/ /*************************************************************************************************/ cout << fixed; cout << showpoint; cout << left; cout << '|' << setw(10) << "NAME"; cout << right; cout << '|' << setw(10) << "Proj 1" << '|' << setw(10) << "Proj 2"; cout << '|' << setw(10) << "Average" << '|' << setw(4) << "GPA" << '|' << endl; cout << "--------------------------------------------------" << endl; // report for the first student cout << left << setprecision(1); cout << '|' << setw(10) << stud_name_1; cout << right; cout << '|' << setw(10) << proj1_score_1 << '|' << setw(10) << proj2_score_1; cout << setprecision(2); cout << '|' << setw(10) << proj_average_score_1 << '|' << setw(4) << gpa_1 << '|' << endl; cout << "--------------------------------------------------" << endl; // report for the second student cout << left << setprecision(1); cout << '|' << setw(10) << stud_name_2; cout << right; cout << '|' << setw(10) << proj1_score_2 << '|' << setw(10) << proj2_score_2; cout << setprecision(2); cout << '|' << setw(10) << proj_average_score_2 << '|' << setw(4) << gpa_2 << '|' << endl; cout << "--------------------------------------------------" << endl; // report for the third student cout << left << setprecision(1); cout << '|' << setw(10) << stud_name_3; cout << right; cout << '|' << setw(10) << proj1_score_3 << '|' << setw(10) << proj2_score_3; cout << setprecision(2); cout << '|' << setw(10) << proj_average_score_3 << '|' << setw(4) << gpa_3 << '|' << endl; cout << "==================================================" << endl; // report for average score in each column cout << left << setprecision(1); cout << '|' << setw(10) << "AVERAGE"; cout << right; cout << '|' << setw(10) << proj1_average_score << '|' << setw(10) << proj2_average_score; cout.unsetf(ios::fixed); // turn off fixed cout.unsetf(ios::showpoint); // turn off showpoint cout << setprecision(2); cout << '|' << setw(10) << proj_average_score << '|' << setw(4) << BLANK << '|' << endl; cout << "==================================================" << endl; cout << endl << endl; return(0); } // main function