Posted By

Desoxena on 01/17/11


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Sereniel


grader program


 / 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"

  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <fstream>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. void gradeInput()
  9. {
  10. char grade;
  11. int f;
  12. float percent, testScore[3];
  13. string fname, lname, infoArray[4];
  14. cout << "\nplease enter in students' first name\n" << endl;
  15. cin >> fname;
  16. cout << "\nplease enter the students last name.\n" << endl;
  17. cin >> lname;
  18. ofstream inFile;
  19. inFile.open("students.txt", ios::app);
  20. cout << "\nplease enter in the test scores.\n" << endl;
  21. cin >> testScore[1];
  22. cin >> testScore[2];
  23. cin >> testScore[3];
  24. float myScore = testScore[1]+testScore[2]+testScore[3];
  25. percent = myScore/3;
  26. if (percent => 90)
  27. {
  28. grade = 'A';
  29. }
  30. else if (percent > 80 && percent < 90)
  31. {
  32. grade = 'B';
  33. }
  34. else if (percent > 70 && percent < 80)
  35. {
  36. grade = 'C';
  37. }
  38. else if (percent > 55 && percent < 70)
  39. {
  40. grade = 'D';
  41. }
  42. else if (percent <= 54)
  43. {
  44. grade = 'F';
  45. }
  46. inFile << lname <<", "<< fname << " - " << grade <<" /"<< percent << "% " << endl;
  47. inFile.close();
  48. }
  49.  
  50. void printGrades()
  51. {
  52. system("cls");
  53. string student;
  54. ifstream outFile ("students.txt");
  55. while (outFile.good())
  56. {
  57. getline (outFile, student);
  58. cout << student << endl;
  59. }
  60. outFile.close();
  61. }
  62. void clear()
  63. {
  64. system("cls");
  65. ofstream myClear;
  66. myClear.open("students.txt");
  67. myClear << "" << endl;
  68. myClear.close();
  69. }
  70. int main()
  71. {
  72. int i = 5;
  73. string command;
  74. cout << "would you like to input or read student grades and information?" << endl;
  75. do{
  76. cin >> command;
  77. if (command == "input")
  78. {
  79. gradeInput();
  80. }
  81. else if (command == "read")
  82. {
  83. printGrades();
  84. }
  85. else if (command == "cleargrades")
  86. {
  87. clear();
  88. }
  89. }while(i==5);
  90. }
  91. // output example: Harris, John - A / 95%

Report this snippet  

You need to login to post a comment.