The assignment is to write a program that implements a C++ class that represents
ID: 3795679 • Letter: T
Question
The assignment is to write a program that implements a C++ class that represents you (as an individual).
1) The name of the class should be Me.
2) The class should contain the following variables as private data members:
- first name
- last name
- middle Initial
- birthday
- gender
- Major
- courses taken
Note: The data type for all the fields of information (except Courses taken) can be of type string for this version. The Courses taken should be stored in either a one or two, two dimensional array of strings. You can assume that a maximum of 5 courses could be taken during each fall and spring semester attended. Therefore, you can use 2, 2-d arrays of size [4][5] each representing fall and spring or one two-dimentional array of size [8][5] with each (row) alternating between fall and spring.
3) At least the following public member functions:
A constructor to initialize the object with specified information.
A constructor to create a default object.
displayMeInfo() // A function to display the pertinent information.
inputCourseInfo() // A function to enter the pertinent Course information.
displayCourses() // A function that displays all the courses taken, listed by semester OR the courses taken during a requested semester.
Explanation / Answer
#include <iostream>
using namespace std;
class Me
{
private:
string firstName;
string lastName;
string middleInitial;
string birthday;
string gender;
string major;
string coursesFall[4][5];
string coursesSpring[4][5];
public:
Me() //default constructor
{
firstName = " ";
lastName = " ";
middleInitial = " ";
birthday = " ";
gender = " " ;
major = " ";
}
//parameterized constructor
Me(string firstName,string lastName,string middleInitial,string birthday,string gender,string major)
{
this->firstName = firstName;
this->lastName = lastName;
this->middleInitial = middleInitial;
this->birthday = birthday;
this->gender = gender;
this->major = major;
}
void inputCourseInfo() //enter courses for Falla nd Spring
{
int i,j;
cout<<" Enter Fall courses";
for(i=0;i<4;i++)
for(j=0;j<5;j++)
cin>>coursesFall[i][j];
cout<<" Enter Spring courses";
for(i=0;i<4;i++)
for(j=0;j<5;j++)
cin>>coursesSpring[i][j];
}
void displayCourses() //display courses
{
int i,j;
cout<<" Fall courses : ";
for(i=0;i<4;i++)
{
for(j=0;j<5;j++)
{
cout<<coursesFall[i][j]<<" ";
}
cout<<endl;
}
cout<<" Spring courses : ";
for(i=0;i<4;i++)
{
for(j=0;j<5;j++)
{
cout<<coursesSpring[i][j]<<" ";
}
cout<<endl;
}
}
void displayMeInfo() // display info
{
cout<<"First Name : "<<firstName;
cout<<" Last name : "<<lastName;
cout<<" Middle Initial "<<middleInitial;
cout<<" Birthday : "<<birthday;
cout<<" gender : "<<gender;
cout<<" Major : "<<major;
}
};
int main()
{
Me me("Alicia","Woodland","J.","23 jan,2001","Female","Computers");
me.inputCourseInfo();
me.displayCourses();
me.displayMeInfo();
return 0;
}
output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.