Results 1 to 5 of 5

Thread: Question i got for Practical test and solution i submitted.

  1. #1
    Join Date
    Sep 2005
    Posts
    2,394
    Rep Power
    0

    Default Question i got for Practical test and solution i submitted.

    Feel free to give opinions and alternate way of doing it.

    Code:
    #include <iostream>
    #include <string>
    #include <iomanip>
    
    using namespace std;
    
    /*TEST 1
    
    Requirements:
    
    Create a class called STUDENT with data members firstname, lastname, age finalcwgrade and 
    finalexgrade and studentID.
    Use a default constructor to initialize firstname to “Usain” and lastname to “Bolt”.  Initialize 
    all other data members to zero.
    Define a mutator that will accept values for the data members from the user and update each data 
    member.
    Define a function CalculateFinalGrade that will sum the final coursework grade and the final exam 
    grade and return the average of both grades.
    Define a utility function that will check if the final grade is above 80, and prints the message 
    “This student is above average”. If the final grade is not above 80, then your program should 
    display “ This is an Average Student”  This utility should be invoked by a display function.
    The display function will display all the student’s information and whether or not the student is 
    average or above average.
    Finally, write a main program that will implement the student class. Invoke the display function 
    before the user enters inputs to display default constructor values and should also be invoked 
    after the user inputs.
    */
    
    class Student {
          private:
              string firstname, lastname;
              static int age, studentID;
              static float finalcwgrade, finalexgrade, finalgrade;
          public:
              Student(){
                  firstname = "Usain";
                  lastname = "Bolt";
              }
              void setStudent(string fname, string lname, int ag, int stID, float cw, float ex){
                  firstname = fname;
                  lastname = lname;
                  age = ag;
                  studentID = stID;
                  finalcwgrade = cw;
                  finalexgrade = ex;              
              }
              float CalculateFinalGrade(){
                    finalgrade = (finalcwgrade + finalexgrade) / 2;
                    return finalgrade;
              }         
              string PerfTest(){
                    if(finalgrade > 80){
                        string assess = "This student is above average";
                        return assess;
                    }  
                    else {
                         string assess = "This is an Average Student";
                         return assess;
                    }
              }
              void Display(){
                   cout << setw(5) << "First Name" << setw(10) << "Last Name" << setw(5) << "Age" << setw(10)
                   << "StudentID" << setw(10) << "CW Grade" << setw(12) << "Exam Grade" << setw(12) <<
                   "Final Grade" << setw(10) << "Status" << endl;
                   cout << setw(5) << firstname << setw(10) << lastname << setw(8) << age << setw(10) << 
                   studentID << setw(10) << finalcwgrade << setw(10) << finalexgrade << setw(10);
                   cout << CalculateFinalGrade();
                   cout << setw(36); 
                   cout << PerfTest();
                   cout << endl << endl;   
              }
    };
    
    int Student::age = 0;
    int Student::studentID = 0;
    float Student::finalcwgrade = 0.0;
    float Student::finalexgrade = 0.0;
    float Student::finalgrade = 0.0;
    
    
    int main(){
         Student stud;
         string fname, lname;
         int age, stID;
         float cw, ex; 
         
         stud.Display();
     
         cout << "Enter First Name: \t";
         cin >> fname;
         cout << endl << endl << "Enter Last Name: \t";
         cin >> lname;
         cout << endl << endl << "Enter Age: \t";
         cin >> age;
         cout << endl << endl << "Enter StudentID: \t";
         cin >> stID;
         cout << endl << endl << "Enter Final Coursework Grade: \t";
         cin >> cw;
         cout << endl << endl << "Enter Final Exam Grade: \t";
         cin >> ex;
         
         cout << endl;
         stud.setStudent(fname, lname, age, stID, cw, ex);
         
         cout << endl;
         stud.Display();
         
         cin.ignore();
         cin.get();
         
         return 0;     
    }
    To find what you seek in the road of life, the best proverb of all is that which says: "Leave no stone unturned." Edward Bulwer Lytton

  2. #2
    Join Date
    Nov 2011
    Posts
    263
    Rep Power
    0

    Default

    I'll take a look at it. When do you need a reply by?
    Phone: Nokia 1200 with Satantendo ROM v.3.3
    Laptop: (Pentium III 850 MHz, 512 MB, 60 GB)
    Console: Sega Dreamcast
    Check out my blog: http://satanforce.wordpress.com/

  3. #3
    Join Date
    Sep 2005
    Posts
    2,394
    Rep Power
    0

    Default

    There is no rush really. As I said I got that question as a practical test on Saturday night and code you see there is what iI submited. Just want feedback on my approach and suggestion on how else it could have been done
    To find what you seek in the road of life, the best proverb of all is that which says: "Leave no stone unturned." Edward Bulwer Lytton

  4. #4
    Join Date
    Jul 2002
    Posts
    1,388
    Rep Power
    0

    Default May I interest you in further experiments/experience?

    Quote Originally Posted by lovepython View Post
    There is no rush really. As I said I got that question as a practical test on Saturday night and code you see there is what iI submited. Just want feedback on my approach and suggestion on how else it could have been done
    Are you familiar with Git? If you are, would you like to host your code that way? Benefits:
    1. Ease in sharing code with others
    2. Better tracking of changes and methods
    3. Multiple versions of 1 file ("God doesn't roll dice")
    4. Backup with ease

    If you are interested create an account at Github.com; then post your repository link.
    Sharing is caring? Then what if I care too much? A precarious situation, indeed...
    http://ip-check.org/ip-check.png

  5. #5
    Join Date
    Sep 2005
    Posts
    2,394
    Rep Power
    0

    Default

    no am not familiar with it. kinda new to programming. will check it out
    To find what you seek in the road of life, the best proverb of all is that which says: "Leave no stone unturned." Edward Bulwer Lytton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •