Advertisement
X6xCyb0r_Gx9X

Course Average Letter Grade

Apr 22nd, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. Function Format
  3. Purpose
  4. To create and execute a C++ program with functions to read student name and scores
  5. input from a keyboard, calculate the test average, program average, course average, and
  6. the letter grade earned and output the result to the monitor as well as to an output text
  7. file. Program must allow grades to be calculated for one or more number of students.
  8. The letter grade earned must be based on the course average (the average of the program
  9. and test scores) as shown below.
  10.  
  11. Course Average Letter Grade
  12. >=90% A
  13. 80% - 89% B
  14. 70% - 79% C
  15. Below 70% F
  16.  
  17. You are required to use a function to accomplish each of the following:
  18. 1. Output descriptive header (void function with no parameters)
  19. 2. Prompt user for name and program/test scores and read the input (void function with
  20. reference parameters)
  21. 3. Check to ensure each input score is not less than 0 or greater than 100. Prompt user to
  22. reenter score if not within specified range (value returning function with parameter)
  23. 4. Calculate averages (void function with value and reference parameters)
  24. 5. Assign letter grade (value returning function with parameter)
  25. 6. Output student name, total points, and program, test, and course averages to monitor
  26. and text file. (void function with value parameters)
  27.  
  28.  
  29.  
  30.  
  31. this is what i have so far
  32.  
  33. #include<iostream>
  34. #include<iomanip>
  35. #include<fstream>
  36. using namespace std;
  37.  
  38. //Global variables/constants, function prototypes
  39. void headerfn();//void function with no parameters
  40. void inputfn(string &fname, string &lname, int &prog1, int &prog2, int &prog3, int &test1, int &test2, int &test3);
  41. float inputfn(string input);
  42. char gradefn(float avg);
  43. void outputfn(float avg, char grade);
  44.  
  45. int main(){
  46. system("color f0");
  47. headerfn();//void function call
  48.  
  49. int prog1, prog2, prog3, test1, test2, test3;
  50. inputfn(prog1, prog2, prog3, test1, test2, test3);
  51.  
  52. string fname, lname;
  53. namefn(fname,lname);//fn call
  54. cout<<"Your first and last name is "<<fname+' '+lname<<endl;// the results
  55.  
  56. float input;
  57. input=inputfn(fname, lname, prog1, prog2, prog3, test1, test2, test3);
  58.  
  59. float average;
  60. char grade;
  61.  
  62. average=coursefn();
  63. cout<<"Avg= "<<average<<endl;
  64.  
  65. grade = gradefn(average);
  66.  
  67. cout<<"Grade = "<<grade<<endl;
  68.  
  69. outputfn(average, grade);
  70.  
  71. system("pause");
  72. return 0;
  73. }//end of main
  74.  
  75. //************************************************************
  76. //Void Function Without Parameters
  77. void headerfn(){
  78. cout<<"123456789012345678901234567890123456789012345678901234567890"<<endl;
  79. cout<<setw(60)<<setfill('*')<<"*"<<endl;
  80. cout<<"* *";
  81. cout<<"* information from the keyboard and outputs *";
  82. cout<<"* the results to the monitor and a text file. *";
  83. cout<<setw(60)<<setfill('*')<<"*"<<endl;
  84. }//end of headerfn
  85.  
  86.  
  87.  
  88.  
  89. //************************************************************
  90. //Void Function With Parameters
  91. void inputfn(string &fname, string &lname, int &prog1, int &prog2, int &prog3, int &test1, int &test2, int &test3){
  92.  
  93. void namefn(string &fname, string &lname){
  94. cout<<" Enter your first and last name: ";
  95. cin>> fname>>lname;
  96. }
  97.  
  98.  
  99.  
  100.  
  101. cout<<"Please enter the first program score: ";
  102. cin>>prog1;
  103. cout<<"Please enter the second program score: ";
  104. cin>>prog2;
  105. cout<<"Please enter the third program score: ";
  106. cin>>prog3;
  107. cout<<"Please enter the first test score: ";
  108. cin>>test1;
  109. cout<<"Please enter the second test score: ";
  110. cin>>test2;
  111. cout<<"Please enter the third test score: ";
  112. cin>>test3;
  113. cout<<fixed<<showpoint<<setprecision(2);
  114. average=(test1+test2+test3)/3;
  115. cout<<"Average: "<<average<<endl;
  116.  
  117. void outputfn(float avg, char grade){
  118. cout<<"Average = "<<avg<<endl;
  119. <<"Grade = "<<grade<<endl;
  120.  
  121. string grade;
  122. if(average>=90){grade="A";}
  123. else if(average>=80){
  124. if(test1>95||test2>=95||test3>=95){grade="A";}
  125. else{grade="B";}
  126. }
  127. else if(average>=70){
  128. if(test1>=85||test2>85){grade="B";}
  129. else{grade="C";}
  130. }
  131. else{grade="F";}
  132.  
  133.  
  134.  
  135.  
  136. //************************************************************
  137. //Value Returning Function With Parameter
  138. float inputfn(string &fname, string &lname, int &prog1, int &prog2, int &prog3,int &test1, int &test2, int &test3){
  139. float input;
  140. if (input<0) cout<<"This score is invalid! PLease enter a score between 0-100: ";
  141. else if (input>100) cout<<"This score is invalid! PLease enter a score between 0-100: ";
  142.  
  143. cout<<"123456789123456789123456789123456789123456789012345678901234\n";
  144. cout<<"============================================================\n";
  145. cout<<endl;
  146.  
  147.  
  148. cout<<left<<setw(25)<<"FIRST NAME"
  149. <<setw(25)<<"LAST NAME"<<endl;
  150. cout<<left<<setw(15)<<firstName
  151. <<setw(15)<<lastName<<endl;
  152. cout<<setw(25)<<setfill('-')<<"-"<<setfill(' ')<<endl;
  153.  
  154. cout<<setw(25)<<setfill('-')<<"-"<<setfill(' ')<<endl;
  155.  
  156.  
  157. cout<<left<<setw(15)<<setfill('-')<<"Program Average"
  158. <<right<<setw(10)<<setfill('-')<<programAverage<<endl<<endl;
  159.  
  160. cout<<left<<setw(15)<<setfill('-')<<"Test Average"
  161. <<right<<setw(10)<<setfill('-')<<testAverage<<endl<<endl;
  162.  
  163. cout<<left<<setw(15)<<setfill('-')<<"Course Average"
  164. <<right<<setw(10)<<setfill('-')<<courseAverage<<endl<<endl;
  165.  
  166. cout<<left<<setw(15)<<setfill('-')<<"Letter Grade"
  167. <<right<<setw(10)<<setfill('-')<<letterGrade<<endl<<endl;
  168.  
  169.  
  170. cout<<"____________________________________________________________\n";
  171.  
  172.  
  173. cout<<"Please enter 1 for another student or 0 to exit: ";
  174. cin>>flag;
  175. }while(flag);
  176.  
  177.  
  178.  
  179. return input;
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement