Develop your own class and use it in a program.
> instantiate object of new class
> initialize object’s initial values
> set object’s values
> print object’s values
> test the integrity of class by trying to set invalid object values
1. Create the header file in figure 9.1.
2. Create the program file in figure 9.3.
2. Compile the programs.
3. Run the program.
4. Capture the results.
Specifications: Part II
Discussion:
For part II, you will get some practice creating classes/header files and using them.
Specifications:
1. Use the class developed in Part I.
2. Create another header file for a date class.
3. Create another header file for a scores class.
4. Write an interactive C++ program;
> instantiate objects of time, date, and scores class
> prompt the user for date and store it
> prompt the user for time and store it
> prompt the user for name of student and store it
> prompt the user for student id number and store it
> prompt the user for score and store it
> the only valid scores are 0 -150
> the main logic of your program must be included within a loop that repeats until the user decides he/she does not want to continue processing students scores.
> when the user is done e//Scores.cpp
//Scores class member function definitions
Code:
#include <iostream>
#include <iomanip>
#include <string>
#include "Scores.h"
using namespace std;
Scores::Scores()
{
lastName, firstName = " ";
score = 0;
}
void Scores::getFirstNameFromUser()
{
string firstName;
cout << "Enter student's first name: " << endl;
cin >> firstName;
setFName(firstName);
}
string Scores::getFirstName()
{
return firstName;
}
void Scores::getLastNameFromUser()
{
string lastName;
cout << "Enter student's last name: " << endl;
cin >> lastName;
}
void Scores::getScoreFromUser()
{
int score;
cout << "Enter student's score: " << endl;
cin >> score;
}
void Scores::getDateTime()
{
int month, day, year;
int hour, minute, second;
cout << "Enter month: " << endl;
cin >> month;
cout << "Enter day: " << endl;
cin >> day;
cout << "Enter year: " << endl;
cin >> year;
//Date studentDate( month, day, year);
cout << "Enter hour: " << endl;
cin >> hour;
cout << "Enter minute: " << endl;
cin >> minute;
cout << "Enter second: " << endl;
cin >> second;
//Time studentTime (hour, minute, second);
}
void Scores::printScore()
{
cout << "Student's name: " << getFirstName() << " " << endl;//<< lastName
//<< " score " << score << endl;
//cout << "Student's name: " << scores.getFirstName << " " << lastName
// << " score " << score << endl; //<< " date and time " << studentDate.printDate();
//month << "/" << day << "/" << year << " " << hour << ":" << minute << ":" << second;
//<< " " << studentTime.printTime();
}
void Scores::setFName(string fname)
{
firstName = fname;
}
void Scores::setLName(string lname)
{
lastName = lname;
}
void Scores::setScore(int inScore)
{
score = inScore;
}
void Scores::setDateTime(int mon, int day, int yr, int hr, int min, int sec)
{
//lastName = lname;
}
ntering scores, print out all student IDs, names, scores, date and time of entry