Advertisement
Guest User

grade

a guest
Oct 9th, 2011
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.51 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class Year
  6. {
  7.     public:
  8.  
  9. Year(string sone, string stwo, string sthree, string sfour, string sfive, string ssix, string sseven, string seight)  // constructor
  10. {
  11.         subjectName[0] = sone;
  12.         subjectName[1] = stwo;
  13.         subjectName[2] = sthree;
  14.         subjectName[3] = sfour;
  15.         subjectName[4] = sfive;
  16.         subjectName[5] = ssix;
  17.         subjectName[6] = sseven;
  18.         subjectName[7] = seight;
  19.  
  20.         sum = 0;
  21.         percentage = 0;
  22. }
  23. void nameOfSem(string semName) // semster name
  24. {
  25.     name = semName;
  26.     cout << "Enter your " << name  << " marks"<< endl;
  27. }
  28. //no of subjects in semster and  store marks in an array
  29. void readMarks(int noOfSubjects)
  30. {
  31.     subjects = noOfSubjects;
  32.     for(int i=0; i<subjects; i++)
  33.     {
  34.         cout << subjectName[i]; // print out subject name stored in the array
  35.         cin >> yearName[i]; // input from keyboard of marks
  36.         // while loop so that user enters marks from 0 to 100
  37.         while (yearName[i]<0 || yearName[i] > 100 )
  38.         {
  39.             cout << "incorrect input please enter again: ";
  40.             cin >> yearName[i];
  41.         }
  42.     }
  43. }
  44.  
  45. // function for calculating avarage
  46. void avarage()
  47. {
  48.     for(int j=0; j<subjects; j++) // addtion of marks (addtion of array)
  49.     {
  50.         sum += yearName[j];
  51.     }
  52.     cout << "the total  is : " << sum << endl;
  53.     percentage = float(sum) / float(subjects);
  54.     cout << "The percentage is :  " << percentage << endl;
  55. }
  56.  
  57.             int sum; // for storing sum of marks
  58.  
  59.             string name; //  for storing name of the semister
  60.             int subjects; // for storing number of subjects in semister
  61.             float percentage; // calculating percentage in the sem
  62.              int yearName[]; // array for string marks
  63.              string subjectName[]; // array for storin g subject names
  64.  
  65. };
  66.  
  67.  
  68. // main function
  69. int main()
  70. {
  71.     cout << "Welcome to xxx uni " << endl;
  72.  
  73.   // constructor for storing subjects name in the array
  74.    Year first("Appiled Physics ", "Electronic Devices circuits ", "Basic electrical Engineering ", "C & Data Structures", "English ", "Mathematical Methods ", "mathematics 1 ", "Engineering Drawing ");
  75.  
  76.   // name of the sem
  77.    first.nameOfSem("First Year");
  78.  
  79.    //no of subjects and storing marks in the array
  80.    first.readMarks(8);
  81.  
  82.    //calculating avarage
  83.    first.avarage();
  84.  
  85.  
  86.  
  87.  
  88. /*
  89.    Year two( " " , " ", " ")
  90.    second year object
  91.  
  92.    */
  93.     return 0;
  94. }
  95.  
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement