Question

C++ Program classes READ THE FOLLOWING CAREFULLY TO GET FULL VALUE FROM THE PRACTICE. IF NOT...

C++ Program

classes

READ THE FOLLOWING CAREFULLY TO GET FULL VALUE FROM THE PRACTICE. IF NOT COMFORTABLE WITH CLASSES,
I WOULD START WITH DEFINING THE CLASS WITH ONE constructor AND GO FROM THERE

Use the following to calculate a GPA (the following is for calculation information only):

A = 4.00 grade points per credit hour
A- = 3.70 grade points per credit hour
B+ = 3.33 grade points per credit hour
B = 3.00 grade points per credit hour
B- = 2.70 grade points per credit hour
C+ = 2.30 grade points per credit hour
C = 2.00 grade points per credit hour
C- = 1.70 grade points per credit hour
D+ = 1.30 grade points per credit hour
D = 1.00 grade points per credit hour
D- = 0.70 grade points per credit hour

gpa calculation = total grade points received (see above)/ number hours attempted
If you took 3 classes; 3 credit hours each; received an 'A' in each class
A = 4.00 points per credit hour means a total of 36 grade points earned
for 9 attempted hours
gpa = 36/9 = 4.0


1. Create a header file (*.h) for a class named Student defined as follows:

Private variables to hold:
first name
last name
street address
city
state
zip
earned grade points
attempted credit hours
gpa

Public methods:

constructor of type Student; set all the private variables to space
or zero, depending on the data type

constructor of type Student; set all name values and all address values
to values passed in as parameters, do not include earned grade point or
attempted credit hours as parameters

constructor of type Student; set ALL private variables to values
passed in as parameters

method to display all private variables of the class (i.e., cout)

method to calculate the gpa (no parameters)

method to calculate the gpa with earned and attempted values passed in as parameters

method to set the earned value; earned value passed in as parameter
  
method to set the attempted value; attempted value passed in as parameter

2. Create an implementation program (*.cpp file) for class Student and code all the public methods.

  
3. Create a client program (*.cpp) that uses class Student. Create three students using each of
the three constructors defined in 1. Be aware of what data gets initialized or set to values.

4. Calculate the gpa for each of the students.

5. Display ALL the data for each of the students after the gpa has been calculated (name, full address,
grade points earned, grade points attempted, gpa)

6. Be aware that if the first two constructors are used, the earned and attempted
values will NOT be set to calculate the gpa. Try using your set methods
to give these a value.
  
You will need to create a project.   

  
If you like to include the following line of code: system("pause");
You MAY need to: #include <cstdlib>

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

#include <iostream>

#include <string>

using namespace std;

//defining class

class Student

{

private:

//private variables

string first_name;

string last_name;

string street_address;

string city;

string state;

string zip;

int earned_grade_points;

int attempted_credit_hours;

double gpa;

public:

//default constructor

Student();

//constructor to set name values and all address values to values passed in as parameters

Student(string, string, string, string, string, string);

//constructor to set all values

Student(string, string, string, string, string, string, int, int);

//overload cout

friend ostream &operator<<(ostream &, const Student &);

//method to calculate gpa

void calculate_gpa();

//method to calculate gpa from given arguments

void calculate_gpa(int, int);

//method to set earned grade points

void set_earned_grade_points(int);

//method to set attempted credit hours

void set_attempted_credit_hours(int);

};

#include <iostream>

using namespace std;

//default constructor

Student::Student()

{

this->first_name = "";

this->last_name = "";

this->street_address = "";

this->city = "";

this->state = "";

this->zip = "";

this->earned_grade_points = 0;

this->attempted_credit_hours = 0;

this->gpa = 0;

}

//constructor to set name values and all address values to values passed in as parameters

Student::Student(string first_name, string last_name, string street_address, string city, string state, string zip)

{

this->first_name = first_name;

this->last_name = last_name;

this->street_address = street_address;

this->city = city;

this->state = state;

this->zip = zip;

}

//constructor to set all values

Student::Student(string first_name, string last_name, string street_address, string city, string state, string zip, int earned_grade_points, int attempted_credit_hours)

{

this->first_name = first_name;

this->last_name = last_name;

this->street_address = street_address;

this->city = city;

this->state = state;

this->zip = zip;

this->earned_grade_points = earned_grade_points;

this->attempted_credit_hours = attempted_credit_hours;

calculate_gpa();

}

//method to calculate gpa

void Student::calculate_gpa()

{

this->gpa = float(this->earned_grade_points) / float(this->attempted_credit_hours);

}

//method to calculate gpa from given arguments

void Student::calculate_gpa(int earned_grade_points, int attempted_credit_hours)

{

this->earned_grade_points = earned_grade_points;

this->attempted_credit_hours = attempted_credit_hours;

calculate_gpa();

}

//method to set earned grade points

void Student::set_earned_grade_points(int earned_grade_points)

{

this->earned_grade_points = earned_grade_points;

}

//method to set attempted credit hours

void Student::set_attempted_credit_hours(int attempted_credit_hours)

{

this->attempted_credit_hours = attempted_credit_hours;

}

//to convert gpa to string ie A,B etc

string to_gpa(double gpa)

{

if (gpa == 4.00)

return "A";

else if (gpa >= 3.7 && gpa < 4.00)

return "A-";

else if (gpa >= 3.33 && gpa < 3.7)

return "B+";

else if (gpa >= 3.00 && gpa < 3.33)

return "B";

else if (gpa >= 2.70 && gpa < 3.00)

return "B-";

else if (gpa >= 2.30 && gpa < 2.70)

return "C+";

else if (gpa >= 2.00 && gpa < 2.30)

return "C";

else if (gpa >= 1.70 && gpa < 2.00)

return "C-";

else if (gpa >= 1.30 && gpa < 1.70)

return "D+";

else if (gpa >= 1.00 && gpa < 1.30)

return "D";

else if (gpa >= .70 && gpa < 1.00)

return "D-";

else

return "Nil";

}

//defination of overload cout<<

ostream &operator<<(ostream &out, const Student &temp)

{

out << "\nStudent\n";

out << "\nName: " << temp.first_name << " " << temp.last_name;

out << "\nAddress " << temp.street_address << endl

<< temp.city << endl

<< temp.state << endl

<< temp.zip << endl;

out << "\nearned_grade_points: " << temp.earned_grade_points << endl;

out << "\nattempted_credit_hours " << temp.attempted_credit_hours << endl;

out << "\nGpa is " << to_gpa(temp.gpa) << endl;

return out;

}

int main()

{

Student first;

Student second("Ramesh", "Kumar", "Street no 7", "Bilaspur", "HP", "185465");

second.calculate_gpa(36, 15);

Student third("Saurab", "Das", "Street no 56", "fiams", "Chandigarh", "54987", 36, 9);

cout << first << second << third;

}

Sample output:

Add a comment
Know the answer?
Add Answer to:
C++ Program classes READ THE FOLLOWING CAREFULLY TO GET FULL VALUE FROM THE PRACTICE. IF NOT...
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
  • java Practice Program 2: Create a project named Student that will cont ain two classes: Student...

    java Practice Program 2: Create a project named Student that will cont ain two classes: Student and StudentClient Student class Instance variables . Name Social security number Gpa Methods: Constructor that accepts all three instance variables Getters for all three instance variables .Setters for name and social security number .Setter for gpa should only set the value if the value is between 0 and 4.0. toString-Outputs the values of the instance variables in this format: name: Smith; SSN: 333-99-4444 GPA:...

  • Task: You want to calculate a student's GPA for a number of classes taken by the...

    Task: You want to calculate a student's GPA for a number of classes taken by the student during a single semester. (In C# (C sharp)) Inputs: 1. the student's name 2. Class names for the classes taken by the student 3. Class letter grade for the classes taken by the student 4. Class credit hours for the classes taken by the student Processing: 1. Accept and process classes until the user indicates they are finished 2. accumulate the number of...

  • You will create a class to store information about a student�s courses and calculate their GPA....

    You will create a class to store information about a student�s courses and calculate their GPA. Your GPA is based on the class credits and your grade. Each letter grade is assigned a point value: A = 4 points B = 3 points C = 2 points D = 1 point An A in a 3 unit class is equivalent to 12 grade points (4 for the A times 3 unit class) A C in a 4 unit class is...

  • Page 1/2 ECE25100 Object Oriented Programming Lab 8: Inheritance Description: The purpose of this lab is...

    Page 1/2 ECE25100 Object Oriented Programming Lab 8: Inheritance Description: The purpose of this lab is to practice inheritance. To get credit for the lab, you need to demonstrate to the student helper that you have completed all the requirements. Question 1: Consider the following detailed inheritance hierarchy diagram in Fig. 1. 1) The Person.java constructor has two String parameters, a first name and a last name. The constructor initializes the email address to the first letter of the first...

  • JAVA :The following are descriptions of classes that you will create. Think of these as service...

    JAVA :The following are descriptions of classes that you will create. Think of these as service providers. They provide a service to who ever want to use them. You will also write a TestClass with a main() method that fully exercises the classes that you create. To exercise a class, make some instances of the class, and call the methods of the class using these objects. Paste in the output from the test program that demonstrates your classes’ functionality. Testing...

  • This is a simple program that I'm struggling with. Java is not my forte... It's way...

    This is a simple program that I'm struggling with. Java is not my forte... It's way too verbose for my liking. Anyways... The criteria for the prog is as follows: No issues with the GUI, I can do this on my own, but for a reference see the following: A combo box should allow the user to select one of the four database actions shown. The database should be implemented as a HashMap, with the ID field as the key...

  • Create a class called Student. This class will hold the first name, last name, and test...

    Create a class called Student. This class will hold the first name, last name, and test grades for a student. Use separate files to create the class (.h and .cpp) Private Variables Two strings for the first and last name A float pointer to hold the starting address for an array of grades An integer for the number of grades Constructor This is to be a default constructor It takes as input the first and last name, and the number...

  • Computer Science 111 Introduction to Algorithms and Programming: Java Programming Net Beans Project #4 - Classes...

    Computer Science 111 Introduction to Algorithms and Programming: Java Programming Net Beans Project #4 - Classes and Objects (15 Points) You will create 3 new classes for this project, two will be chosen (THE TWO CHOSEN ARE TENNIS SHOE AND TREE) from the list below and one will be an entirely new class you invent. Here is the list: Cellphone Clothes JuiceDrink Book MusicBand Bike GameConsole Tree Automobile Baseball MusicPlayer Laptop TennisShoe Cartoon EnergyDrink TabletComputer RealityShow HalloweenCostume Design First Create...

  • /*--------------------------------------------------------------------------- // AUTHOR: // SPECIFICATION: This program is for practicing the use of classes, constructors, //...

    /*--------------------------------------------------------------------------- // AUTHOR: // SPECIFICATION: This program is for practicing the use of classes, constructors, // helper methods, and the this operator. // INSTRUCTIONS: Read the following code skeleton and add your own code // according to the comments //-------------------------------------------------------------------------*/ import java.util.Scanner; public class { public static void main(String[] args) { // Let's make two students using all two constructors // Write code to create a new student alice using constructor #1 //--> Student alice = // Write code to...

  • Write java program The purpose of this assignment is to practice OOP with Array and Arraylist,...

    Write java program The purpose of this assignment is to practice OOP with Array and Arraylist, Class design, Interfaces and Polymorphism. Create a NetBeans project named HW3_Yourld. Develop classes for the required solutions. Important: Apply good programming practices Use meaningful variable and constant names. Provide comment describing your program purpose and major steps of your solution. Show your name, university id and section number as a comment at the start of each class. Submit to Moodle a compressed folder of...

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