Question

Define a class called Student with ID (string), name (string), units (int) and gpa (double). Define...

Define a class called Student with ID (string), name (string), units (int) and gpa (double).

Define a constructor with default values to initialize strings to NULL, unit to 0 and gpa to 0.0.

Define a copy constructor to initialize class members to those of another Student passed to it as parameters.

Overload the assignment operator (=) to assign one Student to another.

Define a member function called read() for reading Student data from the user and a function called print() for printing Student data to screen. These functions will need to work correctly for both Student objects and Student_worker objects as defined below.

Derive a class called Student_worker from Student class with the additional data of weekly_hours (int) and hourly_wage (double).

Define for Student_worker the same constructors and overloading functions as for Student. The constructors must also initialize the additional data of weekly_hours and hourly_wage to 0 and 0.0, respectively. The read and print functions must also read and print the additional data of weekly_hours and hourly_wage.

In main, declare an array of 100 Student pointers and have the program keep creating either a Student or Student_worker, asking each time if the Student being added is a student worker (see the example below), dynamically allocating memory for each, storing the pointer returned by new in the array of Student pointers and reading data for reach by calling the corresponding (the correct) read() function, until no more is desired by answering with a 'n' or 'N' to the question: "Enter a student?".

Display all Students and Student_workers created and read by calling the correct print() function (belonging to Student or Studentn_worker, as the case may be for each).

The following is an example of interaction between the user and the program:

Enter a student? [y/n]: y

Is this a student worker? [y/n]: n

Enter ID, name, units and GPA:

Alice Gordon 101 24 3.3

Enter a student? [y/n]: y

Is this a student worker? [y/n]: n

Enter ID, name, units and GPA:

Robert Palmer 102 18 3.1

Enter a student? [y/n]: y

Is this a student worker? [y/n]: y

Enter ID, name, units and GPA:

Brian Gomez 103 24 3.5

Enter weekly hours: 25

Enter hourly wages: $11.50

Enter a student? [y/n]: y

Is this a student worker? [y/n]: n

Enter ID, name, units and GPA:

Cindy Martinez 104 12 2.9

Enter a student? [y/n]: y

Is this a student worker? [y/n]: n

Enter ID, name, units and GPA:

Jo Smith 105 21 3.7

Enter a student? [y/n]: y

Is this a student worker? [y/n]: y

Enter ID, name, units and GPA:

Mary Mullins 106 18 3.0

Enter weekly hours: 20

Enter hourly wages: $12.50

Enter a student? [y/n]: n

You created the following students:

Alice Gordon, ID: 101, units: 24, GPA: 3.3

Robert Palmer, ID: 102, units: 18, GPA: 3.1

Brian Gomez, ID: 103, units: 24, GPA: 3.5

Weekly hours: 25, hourly wages: $11.50

Cindy Martinez, ID: 104, units: 12, GPA: 2.9

Jo, Smith, ID: 105, units: 21, GPA: 3.7

Mary Mullins, ID: 106, units: 18, GPA: 3.0

Weekly hours: 20, hourly wages: $12.50

Press any key to continue.

Note that student workers have the additional data of weekly hours and hourly wage read and printed. To get full credit, you must have one array of Student pointers and store the pointer for all Student objects - Students and Student_workers - in that one array and your program must read and print the required data for each depending on whether it's a Student or Student_worker and you must provide all required data and member functions.

You do not need to provide separate files but if you do, please, do not zip them. After uploading, press submit. You should see the indication that it's been submitted.

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

Code explained in comments:

// StudentWages.cpp : Defines the entry point for the console application.

//

//#include "stdafx.h"//include if use VisualStudio

#include <iostream>

#include <cstdio>

#include <string>

using namespace std;

class Student {

public:

int ID;

char Name[100];

int Units;

double gpa;

Student()//constructor

{

ID = 0;

Units = 0;

gpa = 0;

}

Student(const Student & str)//copy constructor

{

this->ID = str.ID;

strcpy(this->Name,str.Name);

this->Units = str.Units;

this->gpa = str.gpa;

}

Student operator =(const Student & str)//assignment operator

{

this->ID = str.ID;

strcpy(this->Name, str.Name);

this->Units = str.Units;

this->gpa = str.gpa;

return *this;

}

virtual void Read()//reading the details

{

cout << "Enter Student ID" << endl;

cin >> this->ID;

cout << " Student name" << endl;

cin >> this->Name;

cout << "Units"<<endl;

cin>>this->Units;

cout<<"GPA:" << endl;

cin>>this->gpa;

}

virtual void Print()//printing the student details

{

cout << this->Name<<" ID: "<<this->ID <<" Units " <<this->Units <<" GPA "<< this->gpa << endl;

}

};

class Student_Worker:public Student {//student worker inherited from student

int Weekly_hours;

double Hourly_Wages;

public:

Student_Worker()//constructor

{

Weekly_hours = 0;

double Hourly_Wages = 0;

}

Student_Worker(const Student_Worker & str)//copy constructor

{

this->ID = str.ID;

strcpy(this->Name, str.Name);

this->Units = str.Units;

this->gpa = str.gpa;

this->Weekly_hours = str.Weekly_hours;

this->Hourly_Wages = str.Hourly_Wages;

}

Student_Worker operator =(const Student_Worker & str)//assignement operator

{

this->ID = str.ID;

strcpy(this->Name, str.Name);

this->Units = str.Units;

this->gpa = str.gpa;

this->Weekly_hours = str.Weekly_hours;

this->Hourly_Wages = str.Hourly_Wages;

}

void Read()//reading th details of student worker

{

cout << "Enter Student ID" << endl;

cin >> this->ID;

cout << " Student name" << endl;

cin >> this->Name;

cout << "Units"<<endl;

cin>>this->Units;

cout<<"GPA:" << endl;

cin>>this->gpa;

cout << "WeeklyHours"<<endl;

cin>> this->Weekly_hours;

cout<<"Hourly_Wages" << endl;

cin>> this->Hourly_Wages;

}

void Print()//printing the details

{

cout << this->Name << "ID:" << this->ID << "Units" << this->Units << "GPA" << this->gpa <<"WEEKLY HOURS"<< this->Weekly_hours<<"Hourly Wages:"<< this->Hourly_Wages<<endl;

}

};

int main()

{

Student *s[100];//creating the array ofstudent  

char selector;//selection for student

char selector2;//selection for student worker or not

int i = 0;

while (1)

{

cout << "Enter a student ? [y / n] :" << endl;

cin >> selector;

if (selector == 'y' || selector == 'Y')

{

cout << "Is this a student worker ? [y / n] : " << endl;

cin >> selector2;

if (selector2 == 'y' || selector2 == 'Y')

{

s[i] = new Student_Worker;//creating studentworker object dynamically

s[i]->Read();//calling read

i++;

}

else if (selector2 == 'n' || selector2 == 'N')

{

s[i] = new Student;//creating student object dynamically

s[i]->Read();//calling read to scan details

i++;

}

}

else if (selector == 'n' || selector == 'N')

{

cout << "Exiting the Application\n\n\n" << endl;

break;

}

}

cout << "UptoNow You have created below Objects\n\n\n\n" << endl;

for (int j = 0; j < i; j++)

{

s[j]->Print();//printing the created objects

}

for (int k = 0; k < i; k++)

{

delete s[k];//deleting the dynamica memory allocated for each object

}

//deleting the dynamic memory allocated

system("pause");

return 0;

}

//output:

Quincy 2005 Enter a student? [y / n: Is this a student worker? [y / n] Enter Student ID 181 Student name AliceGordon Units 24

//Output continued:

Add a comment
Know the answer?
Add Answer to:
Define a class called Student with ID (string), name (string), units (int) and gpa (double). Define...
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
  • Please help, provide source code in c++(photos attached) develop a class called Student with the following protected...

    Please help, provide source code in c++(photos attached) develop a class called Student with the following protected data: name (string), id (string), units (int), gpa (double). Public functions include: default constructor, copy constructor, overloaded = operator, destructor, read() to read data into it, print() to print its data, get_name() which returns name and get_gpa() which returns the gpa. Derive a class called StuWorker (for student worker) from Student with the following added data: hours (int for hours assigned per week),...

  • Consider the Tollowing class declaration: class student record public: int age; string name; double gpa; }:...

    Consider the Tollowing class declaration: class student record public: int age; string name; double gpa; }: Implement a void function that initiatizes a dynamic array of student records with the data stored in the file "university body.txt". The function has three formal parameters: the dynamic array "S db, the count, and the capacity. Open and close an ifstream inside the function. Remember, you must allocate memory for the initial size of the dynamic array using "new" inside this function. If...

  • Problem Specification: Write a C++ program to calculate student’s GPA for the semester in your class. For each student, the program should accept a student’s name, ID number and the number of courses...

    Problem Specification:Write a C++ program to calculate student’s GPA for the semester in your class. For each student,the program should accept a student’s name, ID number and the number of courses he/she istaking, then for each course the following data is needed the course number a string e.g. BU 101 course credits “an integer” grade received for the course “a character”.The program should display each student’s information and their courses information. It shouldalso display the GPA for the semester. The...

  • A. Consider “inclass2.h” header file. Define a structure which can hold the following student information: id,...

    A. Consider “inclass2.h” header file. Define a structure which can hold the following student information: id, first name, last name, and gpa. Use appropriate header file guards. ( Max size of first and last name is 20, id is 7 and gpa is double). B. Consider an array of student struct with the MAX_SIZE 10 and a first name. These will be provided as an input to your function. Write a function/method that using the given inputs prints out the...

  • Must be in Python 3 exercise_2.py # Define the Student class class Student():    # Ini...

    Must be in Python 3 exercise_2.py # Define the Student class class Student():    # Initialize the object properties def __init__(self, id, name, mark): # TODO # Print the object as an string def __str__(self): return ' - {}, {}, {}'.format(self.id, self.name, self.mark) # Check if the mark of the input student is greater than the student object # The output is either True or False def is_greater_than(self, another_student): # TODO # Sort the student_list # The output is the sorted...

  • 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...

  • Update your first program to dynamically allocate the item ID and GPA arrays. The number of...

    Update your first program to dynamically allocate the item ID and GPA arrays. The number of items will be the first number in the updated “student2.txt” data file. A sample file is shown below: 3 1827356 3.75 9271837 2.93 3829174 3.14 Your program should read the first number in the file, then dynamically allocate the arrays, then read the data from the file and process it as before. You’ll need to define the array pointers in main and pass them...

  • *** C++ *** Create a class called Student that contains a first name ( string) and...

    *** C++ *** Create a class called Student that contains a first name ( string) and an student id number (type long).     1. Include a member function called get_data( ) to get data from the user for insertion into the object,     2. Also include a function called display_data( ) that displays the student data. Then write a complete program that uses the class to do some computation. Your main function, main( ), should create a Dynamic Array of...

  • 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...

  • #ifndef STUDENTTESTSCORES_H #define STUDENTTESTSCORES_H #include <string> using namespace std; const double DEFAULT_SCORE = 0.0; class StudentTestScores...

    #ifndef STUDENTTESTSCORES_H #define STUDENTTESTSCORES_H #include <string> using namespace std; const double DEFAULT_SCORE = 0.0; class StudentTestScores { private: string studentName; // The student's name double *testScores; // Points to array of test scores int numTestScores; // Number of test scores // Private member function to create an // array of test scores. void createTestScoresArray(int size) { numTestScores = size; testScores = new double[size]; for (int i = 0; i < size; i++) testScores[i] = DEFAULT_SCORE; } public: // Constructor StudentTestScores(string...

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