Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[C++] Modify the Student 'class' files as follows: 1) Add a Major field to the Student class definition. Update the student.h and student.cpp files to

[C++]

Modify the Student 'class' files as follows: 1) Add a Major field to the Student class definition. Update the student.h and student.cpp files to include the additional field. Be sure to include a get and set method for the Major field.

2) Add several majors such as CIS, Math, English, etc. to the students in the array of students located in the main program.

3) When displaying the list of student ID numbers and student names, also display their major. For C++ use the setw( ) function to set the widths of each column so that the columns line up on the screen when displayed. For the C-language, set the parameters for %s in the format string.

4) Change some of the ID numbers and GPAs to illegal values. Have the program detect and display an error message when the illegal values are present.

// Student.h #include  using namespace std; class Student { private: string name; int IdNumber; double gpa; public: // constructors Student(); // default constructor Student(string n, int id, double g); //mutators and accessors void setName(string n); string getName(); void setIdNumber(int id); int getIdNumber(); void setGpa(double g); double getGpa(); }; 

// Student.cpp - contains the code for the Student class member methods #include "stdafx.h" // only for Microsoft Visual Studio C++ programs #include "Student.h" #include  // used by isalpha (test for a character) using namespace std; // default Student constructor Student::Student() { name = ""; // set name to an empty string IdNumber = 0; gpa = 0.0; } // Fully qualified Student constructor Student::Student(string n, int id, double g) { setName(n); // use setName to validate data setIdNumber(id); // use setIdNumber to validate data setGpa(g); // use setGpa to validate data } //mutators and accessors void Student::setName(string n) { if ( isupper(n[0]) ) // 1st character of name must be A-Z name = n; else name = "--Bad name entered"; } string Student::getName() { return name; } void Student::setIdNumber(int id) { if ( id>1 && id<100000) // must be from 0 to 100000 IdNumber = id; else IdNumber = 0; // indicate an illegal selection } int Student::getIdNumber() { return IdNumber; } void Student::setGpa(double g) { if (g>=0.0 && g<=4.0) // gpa must be from 0.0 to 4.0 gpa = g; else gpa = 0; } double Student::getGpa() { return gpa; } 

// Student_Class.cpp : Defines the entry point for the console application. // #include "stdafx.h" // for some versions of Microsoft Visual C++ #include  #include "Student.h" using namespace std; // define an array of students Student CIS054[] = { Student ("Joe Williams", 44536, 3.4), Student ("Sally Washington", 55458, 3.7), Student ("Fred MacIntosh", 66587, 2.9), Student ("Jose De La Cruz", 67892, 3.5), Student ("777 Dan McElroy", 77777, 4.0), Student ("Thinh Nguyen", 73657, 3.6) }; int main(int argc, char* argv[]) { int NumberOfStudents = sizeof(CIS054)/sizeof(Student); // Display the header line // List all the students in the course for (int i=0; i                        

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management System MCQs Multiple Choice Questions And Answers

Authors: Arshad Iqbal

1st Edition

1073328554, 978-1073328550

More Books

Students also viewed these Databases questions

Question

What is the mass of 0.663 m3 of air?

Answered: 1 week ago