Question

In C++, Step 1: Implement the Student Class and write a simple main() driver program to...

In C++,

Step 1:

Implement the Student Class and write a simple main() driver program to instantiate several objects of this class, populate each object, and display the information for each object.

The defintion of the student class should be written in an individual header (i.e. student.h) file and the implementation of the methods of the student class should be written in a corresponding source (i.e. student.cpp) file.

Student class

- The name of the class should be Student.

- The class should be composed of the following (data) members:

student id

first name

last name

middle initial

date of birth in numeric {month, day, year} form

gender, one of {Male, Female}

Note that the data type of each member should be appropriate to the type of data being stored.


and at least the following methods:

Default Constructor

Constructor to initialize the object with at least the name and date of birth of the student.

A method to populate the data members from external (user) input.

Mutator methods for each data member or logical groupings, as necessary. Note that these methods should ensure the integrity of the object and should not allow data to be saved that is not appropriate for that data member. Example, month must be in {1..12}.

Display method to display the contents of the data members.

Step 2:

Implement the following classes:

- Name

- Date

- Program

- Course

- Phone

and update the Student Class as specified.

the class defintion (for each class) should be implemented in an individual header file and the methods of that class in a corresponding source file.

Name class

The name of the class should be Name.

The class should be composed of the following (data) members:

first name

last name

middle initial

Note that the data type of each member should be appropriate to the type of data being stored.

and at least the following methods:

Default Constructor

Constructor to initialize the object with specifed data.

A method to populate the data members from external (user) input.

Mutator methods for each data member or logical grouping, as necessary.

Accessor methods for each data member as needed.

Display method to display the contents of the data members.

Date class

The name of the class should be Date.

The class should be composed of the following (data) members:

month, one of {1 .. 12}

day, one of {1 .. {29,30,31}}

year

Note that the data type of each member should be appropriate to the type of data being stored.

and at least the following methods:

Default Constructor

Constructor to initialize the object with specifed data.

A method to populate the data members from external (user) input.

Mutator methods for each data member or logical grouping, as necessary.

Accessor methods for each data member as needed.

Display method to display the contents of the data members.

Program class

The name of the class should be Program.

The class should be composed of the following (data) members:

campus

Degree, one of {BS, BA}

Major, any major or UNDECLARED

Minor, any minor or NONE

Note that the data type of each member should be appropriate to the type of data being stored.

and at least the following methods:

Default Constructor

Constructor to initialize the object with specifed data.

A method to populate the data members from external (user) input.

Mutator methods for each data member or logical grouping, as necessary.

Accessor methods for each data member as needed.

Display method to display the contents of the data members.

Course class

The name of the class should be Course.

The class should be composed of the following (data) members:

course name

course id

number of credits

instructor

grade received, one of {A,A-,..,F,W}

Note that the data type of each member should be appropriate to the type of data being stored.

and at least the following methods:

Default Constructor

Constructor to initialize the object with specifed data.

A method to populate the data members from external (user) input.

Mutator methods for each data member or logical grouping, as necessary.

Accessor methods for each data member as needed.

Display method to display the contents of the data members.

Phone class

The name of the class should be Phone.

The class should be composed of the following (data) members:

area code

exchange

line

maximum number of texts allowed, a constant data member that represents the maximum possible number of text messages allowed on this phone. Unless specified, the default value should be ten (10).

Note that the data type of each member should be appropriate to the type of data being stored.

and at least the following methods:

Default Constructor

Constructor to initialize the object with specifed data.

A method to populate the data members from external (user) input.

Mutator methods for each data member or logical grouping, as necessary.

Accessor methods for each data member as needed.

Display method to display the contents of the data members.

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:
   int id;
   string firstName;
   string lastName;
   string middle_initial;
   int month;
   int day;
   int year;
   string gender;

public:
   Student();//default constructor
   Student(int , string ,string ,string ,   int ,int ,   int ,string );
   void userInput(int , string ,string ,string ,   int ,int ,   int ,string);
   void set_id(int );
   void set_firstname(string);
   void set_lastname(string);
   void set_middle_initial(string);
   void set_month(int);
   void set_day(int);
   void set_year(int);
   void set_gender(string);
   int get_id();
   int get_year();
   int get_month();
   int get_day();
   string get_fname();
   string get_lname();
   string get_mname();
   string get_gender();
   void display();
   };
#endif

//Student.cpp


#include<iostream>
#include<string>
#include"Student.h"
using namespace std;
Student :: Student()//Default Constructor
{
   this->id=0;
   this->firstName="";
   this->lastName="";
   this->middle_initial="";
   this->month=1;
   this->day=1;
   this->year=0;
   this->gender="";
}


   Student::Student(int id, string firstName,string lastName,string middle_initial,   int month,int day,   int year,string gender)
{
   this->id=id;
   this->firstName=firstName;
   this->lastName=lastName;
   this->middle_initial=middle_initial;
   this->month=month;
   this->day=day;
   this->year=year;
   this->gender=gender;
}

   void Student ::set_id(int id)
   {
       this->id=id;
   }
   void Student::set_day(int day)
   {
       if(day>31 || day<1)
           cout<<"invalid day"<<endl;
       else
       this->day = day;
   }
   void Student::set_firstname(string fname)
   {
       this->firstName=fname;
   }
   void Student::set_lastname(string lname)
   {
       this->lastName=lname;
   }
   void Student::set_middle_initial(string mname)
   {
       this->middle_initial=mname;
   }
   void Student::set_month(int m)
   {
       if(m>12 || m<1)
           cout<<"invalid month";
       else
           this->month=m;
   }
   void Student::set_year(int y)
   {
       this->year=y;

   }
   void Student:: set_gender(string g)
   {
       this->gender=g;
   }
   int Student::get_id()
   {
       return id;
   }
   int Student::get_day()
   {
       return day;
   }
   int Student::get_month()
   {
       return month;
   }
   int Student::get_year()
   {
       return year;
   }
   string Student:: get_fname()
   {
       return firstName;
   }
   string Student::get_lname()
   {
       return lastName;
   }
   string Student::get_mname()
   {
       return middle_initial;
   }
   string Student::get_gender()
   {
       return gender;
   }
   void Student::userInput(int id, string firstName,string lastName,string middle_initial,   int month,int day,   int year,string gender)
   {
       this->id=id;
   this->firstName=firstName;
   this->lastName=lastName;
   this->middle_initial=middle_initial;
   this->month=month;
   this->day=day;
   this->year=year;
   this->gender=gender;
      
   }
   void Student::display()//display function to display the value of data members
   {
       cout<<"Student's first name -->"<<firstName<<endl<<" last name :--> "<<lastName <<endl<<" middle name is-->"<<middle_initial<<endl;
       cout<<"Student's DOB is (DD/MM/YYYY)-->"<<day<<"/"<<month<<"/"<<year<<endl<<" and gender is -->"<<gender<<endl;
   }

//main.cpp

#include<iostream>
#include<string>
#include"Student.h"
using namespace std;
void main()
{
  
   Student student(23,"john","Marks","tams", 11,23,2003,"male");//overload constructor
   int m,d,y,id;
   string fname,mname,lname,gender;
   cout<<"Enter Student's id :-->"<<endl;
   cin>>id;
   student.set_id(id);
   cout<<"Enter Student's date_of_birth in mm dd yyyy :-->"<<endl;
   cin>>m;
   cin>>d;
   cin>>y;
   student.set_month(m);
   student.set_day(d);
   student.set_year(y);
   cout<<"Enter student's first name-->"<<endl;
  
   cin>>fname;
  
   student.set_firstname(fname);
   cout<<"Enter student's last name-->"<<endl;
       cin>>lname;
   student.set_lastname(lname);
   cout<<"Enter student's middle name-->"<<endl;
   cin>>mname;
   student.set_middle_initial(mname);
   cout<<"Enter student's gender-->"<<endl;
   cin>>gender;
   student.set_gender(gender);
   cout<<"Student's detail:-->"<<endl;
   cout<<"Student's First Name -->"<<student.get_fname()<<endl<<" last name-->"<<student.get_lname()<<endl<<" Middle name -->"<<student.get_mname()<<endl;
   cout<<"Student's DOB is (dd/mm/yyyy-->"<<student.get_day()<<"/"<<student.get_month()<<"/"<<student.get_year()<<" and gender is "<<student.get_gender()<<endl;
   student.display();//call display function to print value of data members
}

Step -->2

//Course.h

#ifndef _COURSE
#define _COURSE
#include<iostream>
using namespace std;
class Course
{
private:
   string course_name;
   int course_id;
   int number_of_credits;
   string instructor;
   string grade;
public:
   Course ();
   Course(string,int ,int , string, string);
   string get_course_name();
   int get_course_id();
   int get_number_of_credit();
   string get_instructor();
   string get_grade();

   void set_course_name(string);
   void set_course_id(int);
   void set_number_of_credit(int);
   void set_instructor(string);
   void set_grade(string);
   void display();
};

#endif

//Course.cpp

#include<iostream>
#include<string>
#include"Course.h"
using namespace std;

Course::Course()
{
   course_name="";
   course_id=0;
   number_of_credits=0;
   instructor="";
   grade="";
}
Course::Course(string cname,int cid, int credit, string ins, string gr)

{
   course_name=cname;
   course_id=cid;
   number_of_credits=credit;
   instructor=ins;
   grade=gr;
}

void Course ::set_course_name(string cname)
{
   course_name=cname;
}

void Course::set_course_id(int cid)
{
   course_id=cid;
}
void Course::set_number_of_credit(int credit)
{
   number_of_credits=credit;
}
void Course ::set_instructor(string ins)
{
   instructor=ins;
}
void Course::set_grade(string gr)
{
   grade=gr;
}
string Course::get_course_name()
{
   return course_name;
}

int Course ::get_course_id()
{
   return course_id;
}
int Course :: get_number_of_credit()
{
   return number_of_credits;
}
string Course::get_instructor()
{
   return instructor;
}
string Course::get_grade()
{
   return grade;
}
void Course:: display()
{

   cout<<"Course name --> "<<course_name<<endl<<"course id is -->"<<course_id<<endl;
   cout<<"Number of credit is -->"<<number_of_credits<<endl<<"Instructor Name--> "<<instructor<<endl<<" and grade -->"<<grade<<endl;


}

//Date.h

#ifndef _MY_DATE
#define _MY_DATE
class Date
{
private:
   int month;
   int day;
   int year;
public:
   Date();//Default constructor
   Date(int, int, int);//overload constructor
   int get_day();
   int get_month();
   int get_year();
   void set_day(int);
   void set_month(int);
   void set_year(int);
   void display();
};


#endif

//Date.cpp

#include<iostream>
#include"Date.h"
using namespace std;
Date::Date()
{
   month=12;
   year=2000;
   day=10;
}
Date ::Date(int d, int m, int y)
{
   day=d;
   month=m;
   year=y;
}
void Date::set_day(int d)
{
   if(d>31||d<1)
       cout<<"Invalid Day"<<endl;
   else
       day=d;
}
void Date::set_month(int m)
{
   if(m<1 ||m>12)
       cout<<"Invalid month"<<endl;
   else
       month=m;
}
void Date::set_year(int y)
{
   year=y;
}
int Date::get_day()
{
   return day;
}
int Date::get_month()
{
   return month;
}
int Date::get_year()
{
   return year;
}
void Date::display()
{
   cout<<"The DOB is -->(DD/MM/YYYY)" <<day<<"/"<<month<<"/"<<year<<endl;
}

//Name.h

#ifndef _NAME
#define _NAME
#include<iostream>
using namespace std;
class Name
{
private:
   string firstname;
   string lastname;
   string middle_initial;
public:
   Name();
   Name(string, string, string);
   void set_first_name(string);
   void set_middle_name(string);
   void set_last_name(string);
   string get_first_name();
   string get_middle_name();
   string get_last_name();
   void display();
};


#endif

//Name.cpp

#include<iostream>
#include"Name.h"
#include<string>
using namespace std;

Name::Name()
{
   firstname="";
   middle_initial="";
   lastname="";
}
void Name::set_first_name(string fname)
{
   firstname=fname;
}
void Name::set_middle_name(string mname)
{
   middle_initial=mname;
}
void Name::set_last_name(string lname)
{
   lastname=lname;
}
string Name::get_first_name()
{
   return firstname;
}
string Name::get_middle_name()
{
   return middle_initial;
}
string Name::get_last_name()
{
   return lastname;
}
void Name::display()
{
   cout<<"First name is-->"<<firstname<<endl;
   cout<<"Middle name is-->"<<middle_initial<<endl;
   cout<<"last name is -->"<<lastname<<endl;
}

//phone.h

#ifndef _PHONE
#define _PHONE
#include<iostream>
using namespace std;
class Phone
{
private:
   string area_code;
   string exchange;
   string line;
public:
   Phone();
   Phone(string,string,string);
   string get_area_code();
   string get_exchange();
   string get_line();
   void set_area_code(string);
   void set_exchange(string);
void set_line(string);
void display();


};
#endif

//phone.cpp

#include<iostream>
#include"Phone.h"
#include<string>
using namespace std;
Phone::Phone()
{
   area_code="";
   exchange="";
   line="";
}
Phone::Phone(string area, string ex, string li)
{
   area_code=area;
   exchange=ex;
   line=li;
}
string Phone:: get_area_code()
{
   return area_code;
}
   string Phone ::get_exchange()
   {
       return exchange;
   }
   string Phone ::get_line()
   {
       return line;
   }
   void Phone:: set_area_code(string area)
   {
       area_code=area;
   }
   void Phone ::set_exchange(string ex)
   {
       exchange=ex;
   }
void Phone::set_line(string li)
{
   line=li;
}
void Phone::display()
{
   cout<<"Area Code is -->"<<area_code<<endl<<"Exchange is-->"<<exchange<<endl<<"line is -->"<<line<<endl;
}

//Program.h

#ifndef _PROGRAM
#define _PROGRAM
#include<iostream>
using namespace std;
class Program
{
private:
   string Degree;
   string Major;
   string Minor;
public:
   Program ();
   Program(string,string,string);
   string get_Degree();
   string get_Major();
   string get_Minor();
   void set_Degree(string);
   void set_Major(string);
   void set_Minor(string);
   void display();
};

#endif

//Program.cpp

#include<iostream>
#include"Program.h"
#include<string>
using namespace std;

Program ::Program()
{
   Degree="";
   Major="";
   Minor="";
}
Program::Program(string deg, string maj, string min)
{
   Degree=deg;
   Major=maj;
   Minor=min;
}
void Program::set_Degree(string deg)
{
   Degree=deg;
}
void Program::set_Major(string maj)
{
Major=maj;
}
void Program ::set_Minor(string min)
{
   Minor=min;
}
string Program:: get_Degree()
{
   return Degree;
}
string Program:: get_Major()
{
   return Major;
}
string Program:: get_Minor()
{
   return Minor;
}

void Program :: display()
{
   cout<<"The Degree is-->"<<Degree<<endl<<" Major is -->"<<Major<<endl<<" and the minor is -->"<<Minor<<endl;
}

//Student.h

#ifndef STUDENT_H
#define STUDENT_H
#include<iostream>
#include"Name.h"
#include"Course.h"
#include"Date.h"
#include"Phone.h"
#include"Program.h"
using namespace std;
class Student
{
private:
   Name name;
   Date date;
   Phone phone;
   Program program;
   Course course;

public:
   void set_name(Name);
  
Name get_name();
void set_date(Date);
  
Date get_date();
void set_phone(Phone);
  
Phone get_phone();
void set_program(Program);
  
Program get_program();
void set_course(Course);
  
Course get_course();
   void display();
   };
#endif

//Student.cpp


#include<iostream>
#include<string>
#include"Student.h"
using namespace std;
#include<iostream>
#include"Name.h"
#include"Student.h"
using namespace std;


void Student::display()
{
   name.display();
   date.display();
   course.display();
   program.display();
   phone.display();
}
Name Student::get_name()
{
   return name;
}
void Student::set_name(Name name)
{
   this->name=name;
}
void Student:: set_date(Date d)
{
   date=d;
}
  

Date Student:: get_date()
{
   return date;
}
void Student::set_phone(Phone ph)
{
   phone=ph;
}
  
Phone Student:: get_phone()
{
   return phone;
}
void Student::set_program(Program p)
{
   program=p;
}
  
Program Student::get_program()
{
   return program;
}
void Student::set_course(Course c){
   course=c;
}
  
Course Student:: get_course()
{
   return course;
}

//main.cpp

#include<iostream>
#include<string>
#include"Student.h"
using namespace std;
void main()
{
   Name name;
   Date date;
   Phone phone;
   Program program;
   Course course;

//you can also use overload constructor to intialize values
   name.set_first_name("Palak");
   name.set_last_name("Sahani");
   name.set_middle_name("R");
   date.set_day(12);
   date.set_month(11);
   date.set_year(2002);
   phone.set_area_code("0571");
   phone.set_exchange("New");
   phone.set_line("connected");
   program.set_Degree("BS");
   program.set_Major("undecalred");
   program.set_Minor("Not available");
   course.set_course_name("Compter Science");
   course.set_course_id(415);
   course.set_grade("A");
   course.set_instructor("My instructor");
   course.set_number_of_credit(10);
   Student student;
   student.set_name( name);
   student.set_course(course);
   student.set_date(date);
   student.set_phone(phone);
   student.set_program(program);
   student.display();
  

}

output:-->CAWINDOWS1 system321cmd.exe First name is->Palak Middle name is-- last name is The DOB is --〉(DD/MM/YYYY ) 12/11/2002 Course

//As you asked in comment --.

//actually we want create our own kind of data types instead of using predefined datatypes. So we did it.

Add a comment
Know the answer?
Add Answer to:
In C++, Step 1: Implement the Student Class and write a simple main() driver program to...
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 with this assignment. Thanks. 1. Write a C++ program containing a class Invoice and...

    Please help with this assignment. Thanks. 1. Write a C++ program containing a class Invoice and a driver program called invoiceDriver.cpp. The class Invoice is used in a hardware store to represent an invoice for an item sold at the store. An invoice class should include the following: A part number of type string A part description of type string A quantity of the item being purchased of type int A price per item of type int A class constructor...

  • Write a program

    1. Write a program which have a class named as “Student”, while the data members of the class are,a. char name[10],b. int age;c. string color;d. string gender;e. double cgpa;and the member function “print()”,  is just to display these information.1. You need to create 3 objects of the “Student” class.2. Initialize one object by the default constructor having some static values.3. Initialize the second object by the parameterized constructor, while you need to pass values for initialization.4. Initialize the third object...

  • Write a class named PhoneBookEntry that has fields for a person's name and phone number.The class...

    Write a class named PhoneBookEntry that has fields for a person's name and phone number.The class should have a constructor and appropriate accessor and mutator methods. Thenwrite a program that creates at least five PhoneBookEntry objects and stores them in anArrayLitt. Use a loop to display the contents of each object in the ArrayList.

  • The Drive‑Rite Insurance Company provides automobile insurance policies for drivers. Design a single class diagram showing...

    The Drive‑Rite Insurance Company provides automobile insurance policies for drivers. Design a single class diagram showing the class, the application program, the relationship between the two, and multiplicity. Insert the completed class diagram into a Word document. Then write the pseudocode as described below. Be sure to follow the CSI 117 Style Criteria (Links to an external site.)Links to an external site. for naming conventions, class diagrams, pseudocode, keywords, and operators. a.      Create a PolicyHolder class that contains a policy number,...

  • Overload a relational operator for the Job class: Assume that this operator is not overloaded for...

    Overload a relational operator for the Job class: Assume that this operator is not overloaded for the Salary class. a) Write how the function will be declared in your code. b) Write an external function definition (not inside the class). solve it in C++10 to solve this you nedd question number 1. Create a composition between the classes Job and Salary. Class Salary a. data member:    1. money b. constructors:    1. default constructor    2. user defined constructor with a parameter...

  • Write a C++ program Write a class named Employee that has the following member variables: name...

    Write a C++ program Write a class named Employee that has the following member variables: name A string that holds the employee name idNumber An int to hold employee id number department A string to hold the name of the department position A string to hold the job position The class will have three constructors: 1. A constructor that accepts all the internal data such as: Employee susan("Susan Meyers", 47899, "Accounting", "Vice President"); 2. A constructor that accepts some of...

  • in c++ Define and implement the class Employee with the following requirements: private data members string...

    in c++ Define and implement the class Employee with the following requirements: private data members string type name a. b. double type hourlyRate 2. public member functions a. default constructor that sets the data member name to blank"and hourlyRate to zero b. A constructor with parameters to initialize the private data members c. Set and get methods for all private data members d. A constant method weeklyPay() that receives a parameter representing the number of hours the employee worked per...

  • Define a class named Payment that contains an instance variable "paymentAmount" (non-static member variable) of type...

    Define a class named Payment that contains an instance variable "paymentAmount" (non-static member variable) of type double that stores the amount of the payment and appropriate accessor (getPaymentAmount() ) and mutator methods. Also create a method named paymentDetails that outputs an English sentence to describe the amount of the payment. Override toString() method to call the paymentDetails() method to print the contents of payment amount and any other details not included in paymentDetails(). Define a class named CashPayment that is...

  • Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   and please put comment with code! Problem:2 1. Class Student Create...

    Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   and please put comment with code! Problem:2 1. Class Student Create a "Hello C++! I love CS52" Program 10 points Create a program that simply outputs the text Hello C++!I love CS52" when you run it. This can be done by using cout object in the main function. 2. Create a Class and an Object In the same file as...

  • C++ Programing In this exercise, you will design a class memberType. The class has the following...

    C++ Programing In this exercise, you will design a class memberType. The class has the following data members: memberName. A string that holds the name of a person memberID. A string that holds the member identification number numBooks. An int that holds the number of books bought purchaseAmt. A double that holds the amount spent on books In addition, the class should have the following constructor and other member functions. Constructor. The constructor should accept the person’s name and member...

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