BHXSpecter

Learning structs

Sep 13th, 2011
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. struct studentType
  7. {
  8.     string firstName;
  9.     string lastName;
  10.     char courseGrade;
  11.     int testScore;
  12.     int programmingScore;
  13.     double GPA;
  14. };
  15.  
  16. void readIn(studentType& student);
  17. void printStudent(studentType& student);
  18. studentType setStudentCpy(studentType& student);
  19.  
  20. int main()
  21. {
  22.     studentType newStudent;
  23.     studentType copyStudent;
  24.    
  25.     readIn(newStudent);
  26.     printStudent(newStudent);
  27.     copyStudent = setStudentCpy(newStudent);
  28.     printStudent(copyStudent);
  29.    
  30.     return 0;
  31. }
  32.  
  33. void readIn(studentType& student)
  34. {
  35.     int score;
  36.     cout << "Enter your first name: ";
  37.     cin >> student.firstName;
  38.     cout << "Enter your last name: ";
  39.     cin >> student.lastName;
  40.     cout << "Enter test score: ";
  41.     cin >> student.testScore;
  42.     cout << "Enter programming score: ";
  43.     cin >> student.programmingScore;
  44.     cout << "Enter your GPA: ";
  45.     cin >> student.GPA;
  46.    
  47.     score = (student.testScore + student.programmingScore) / 2;
  48.    
  49.     if (score >= 90)
  50.         student.courseGrade = 'A';
  51.     else if (score >= 80)
  52.         student.courseGrade = 'B';
  53.     else if (score >= 70)
  54.         student.courseGrade = 'C';
  55.     else if (score >= 60)
  56.         student.courseGrade = 'D';
  57.     else
  58.         student.courseGrade = 'F';
  59.        
  60. }
  61.        
  62. void printStudent(studentType& student)
  63. {
  64.     cout << student.firstName << endl << student.lastName
  65.          << endl << student.courseGrade << endl << student.testScore
  66.          << endl << student.programmingScore << endl << student.GPA
  67.          << endl;
  68. }
  69. studentType setStudentCpy(studentType& student)
  70. {
  71.     return student;
  72. }
Add Comment
Please, Sign In to add comment