Question

A hard c++ problem ◎Write a c++ program”Student.h”include Private data member, string firstName; string lastName; double...

A hard c++ problem

◎Write a c++ program”Student.h”include

Private data member,

string firstName;

string lastName;

double GPA(=(4.0*NumberOfAs+3.0*NumberOfBs+2.0*NumberOfCs+1.0*NumberOfDs)/(

As+Bs+Cs+Ds+Fs));

Public data member,

void setFirstName(string name);

string getFirstName() const;

void printFirstName() const;

void getLastName(string name);

string getLastName() const;

void printLastName() const;

void computeGPA(int NumberOfAs,int NumberOfBs,int NumberOfCs,int NumberOfDs,int NumberOfFs);

double getGPA() const;

double printGPA() const;

A destructor and an explicit default constructor initializing GPA=0.0 and checking if GPA>=0.0 by try{}catch{}.

Add member function,

bool operator<(const Student);

The comparison in this function based on the GPAs of two student objects.

◎Implement the Student class in”Student.cpp”

◎Write a test program “StudentTest.cpp”to test member functions and create two student obgects,student1 and student2,compute two students’ GPAs,and show the name of the student name with a higher GPA.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Student.h:

#ifndef STUDENT_H
#define STUDENT_H
#include <iostream>
using namespace std;

class Student
{
private:

    string firstName;

    string lastName;

    double GPA;

public:

    Student(int NumberOfAs,int NumberOfBs,int NumberOfCs,int NumberOfDs,int NumberOfFs)
    {
        computeGPA(NumberOfAs, NumberOfBs, NumberOfCs, NumberOfDs,NumberOfFs);
        GPA = getGPA();
        if (GPA<0)
        {
            cout << "An invalid GPA has been detected. " <<endl;
            GPA = 0.0;
        }
    }

    ~Student()
    {
    }

    void setFirstName(string name)
    {
        firstName = name;
    }

    string getFirstName() const
    {
        return firstName;
    }

    void printFirstName() const
    {
        cout<<"First Name: "<<firstName<<endl;
    }

    void getLastName(string name)
    {
        lastName = name;
    }

    string getLastName() const
    {
        return lastName;
    }

    void printLastName() const
    {
        cout<<"Last Name: "<<lastName<<endl;
    }

    void computeGPA(int NumberOfAs,int NumberOfBs,int NumberOfCs,int NumberOfDs,int NumberOfFs)
    {
        GPA = (4.0*NumberOfAs+3.0*NumberOfBs+2.0*NumberOfCs+1.0*NumberOfDs)/(NumberOfAs+NumberOfBs+NumberOfCs+NumberOfDs+NumberOfFs);
    }
    double getGPA() const
    {
        return GPA;
    }
    double printGPA() const
    {
        cout<<"GPA of "<<getFirstName()<<" "<<getLastName()<<" is: "<<getGPA()<<endl;
    }
    bool operator <(const Student& S2) {
        if(GPA < S2.GPA) {
            return true;
        }
        return false;
    }
};
#endif

StudentTest.cpp:

#include <iostream>
#include "Student.h"

using namespace std;

int main()
{
    
   Student S1(2,3,4,5,0);

   Student S2(3,2,5,4,0);
   S1.setFirstName("Vishnu");
   S1.setLastName("Koduri");
   S2.setFirstName("Shyam");
   S2.setLastName("Sankar");
   S1.printGPA();
   S2.printGPA();
   if( S1 < S2 ) {
      cout << "S1 is less than S2 " << endl;
   } else {
      cout << "S2 is less than S1 " << endl;
   }
    return 0;
}

Output:

Add a comment
Know the answer?
Add Answer to:
A hard c++ problem ◎Write a c++ program”Student.h”include Private data member, string firstName; string lastName; double...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hello, How can I make the program print out "Invalid data!!" and nothing else if the...

    Hello, How can I make the program print out "Invalid data!!" and nothing else if the file has a grade that is not an A, B, C, D, E, or F or a percentage below zero? I need this done by tomorrow if possible please. The program should sort a file containing data about students like this for five columns: one for last name, one for first name, one for student ID, one for student grade percentage, one for student...

  • This is a simple C++ class using inheritance, I have trouble getting the program to work....

    This is a simple C++ class using inheritance, I have trouble getting the program to work. I would also like to add ENUM function to the class TeachingAssistant(Derived class) which is a subclass of Student(Derived Class) which is also a subclass of CourseMember(Base Class). The TeachingAssistant class uses an enum (a user-defined data type) to keep track of the specific role the TA has: enum ta_role {LAB_ASSISTANT, LECTURE_ASSISTANT, BOTH}; You may assume for initialization purposes that the default role is...

  • Please implement the following problem in basic C++ code and include detailed comments so that I...

    Please implement the following problem in basic C++ code and include detailed comments so that I am able to understand the processes for the solution. Thanks in advance. // personType.h #include <string> using namespace std; class personType { public: virtual void print() const; void setName(string first, string last); string getFirstName() const; string getLastName() const; personType(string first = "", string last = ""); protected: string firstName; string lastName; }; // personTypeImp.cpp #include <iostream> #include <string> #include "personType.h" using namespace std; void...

  • Use main.cpp, Student.h, Student.cpp (written below) and write classes StudentClub and a non-member function find youngest...

    Use main.cpp, Student.h, Student.cpp (written below) and write classes StudentClub and a non-member function find youngest to make main.cpp compile. Put the declaration and definition of find youngest in StudentClub.h and StudentClub.cpp separately. You may not modify provided files and only submit StudentClub.h and StudentClub.cpp. Non-member function find youngest is declared as follows. It returns the names of students who have the youngest age. Note there may exist more than one students who are youngest. std::vector find_youngest(const std::vector member); StudentClub...

  • Create the Employee class: The Employee class has three attributes: private: string firstName; string lastName; string...

    Create the Employee class: The Employee class has three attributes: private: string firstName; string lastName; string SSN; The Employee class has ▪ a no-arg constructor (a no-arg contructor is a contructor with an empty parameter list): In this no-arg constructor, use “unknown” to initialize all private attributes. ▪ a constructor with parameters for each of the attributes ▪ getter and setter methods for each of the private attributes ▪ a method getFullName() that returns the last name, followed by a...

  • help please Program Requirements You are given 1 file: Lab1Tests.java. You need to complete 1 file:...

    help please Program Requirements You are given 1 file: Lab1Tests.java. You need to complete 1 file: UWECPerson.java uWECPerson.java UWECPerson uwecld: int firstName: String lastName : String +UWECPerson(uwecld: int, firstName : String, lastName: String) +getUwecid): int setUwecld(uwecld: int): void +getFirstName): String +setFirstName(firstName: String): void getLastName): String setLastName(lastName: String): void +toString): String +equals(other: Object): boolean The constructor, accessors, and mutators behave as expected. The equals method returns true only if the parameter is a UWECPerson and all instance variables are equal. The...

  • Greetings, everybody I already started working in this program. I just need someone to help me...

    Greetings, everybody I already started working in this program. I just need someone to help me complete this part of the assignment (my program has 4 parts of code: main.cpp; Student.cpp; Student.h; StudentGrades.cpp; StudentGrades.h) Just Modify only the StudentGrades.h and StudentGrades.cpp files to correct all defect you will need to provide implementation for the copy constructor, assignment operator, and destructor for the StudentGrades class. Here are my files: (1) Main.cpp #include <iostream> #include <string> #include "StudentGrades.h" using namespace std; int...

  • Complete Course.cpp by implementing the PrintRoster() function, which outputs a list of all students enrolled in a course and also the total number of students in the course.

    Complete Course.cpp by implementing the PrintRoster() function, which outputs a list of all students enrolled in a course and also the total number of students in the course.Given files: main.cpp - contains the main function for testing the program.Course.cpp - represents a course, which contains a vector of Student objects as a course roster. (Type your code in here)Course.h - header file for the Course class.Student.cpp - represents a classroom student, which has three data members: first name, last name, and...

  • Instructions: Consider the following C++ program. At the top you can see the interface for the...

    Instructions: Consider the following C++ program. At the top you can see the interface for the Student class. Below this is the implementation of the Student class methods. Finally, we have a very small main program. #include <string> #include <fstream> #include <iostream> using namespace std; class Student { public: Student(); Student(const Student & student); ~Student(); void Set(const int uaid, const string name, const float gpa); void Get(int & uaid, string & name, float & gpa) const; void Print() const; void...

  • Files given in this assignment (right-click on the file to download) Assignment7.cpp (need to complete) Student.h...

    Files given in this assignment (right-click on the file to download) Assignment7.cpp (need to complete) Student.h (Given. Just use it, don't change it!) Student.cpp (Partially filled, need to complete) 1. Assignment description In this assignment, you will write a simple class roster management system for ASU CSE100. Step #1: First, you will need to finish the design of class Student. See the following UML diagram for Student class, the relevant header file (class declaration) is given to you as Student.h,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT