i've been given an assignment, and an entire code. the only thing i have to do is code methods to make the program work. could someone give me an example of what one of these methods would be? i don't understand it. i have a ton to write, but i think once i understand what exactly a method is and how to use it, i can do the rest. this is the code that's given, and this is the assignment
CSCI 240 - Spring 2010 - Program 11
Code:#include <iostream> #include <iomanip> #include <fstream> using namespace std; //**************************************************************************** //* //* The Time Class Definition //* //**************************************************************************** class Time { public: Time(); //default constructor Time(int, int, char); int toMilitary(int, int, char); void toStandard(int, int &, int &, char &); void display(); void setTime(int, int, char); void setHours(int); void setMinutes(int); void setAMorPM(char); void setMilitary(int); int getHours(); int getMinutes(); char getAMorPM(); int getMilitary(); private: int hours; //hour value for standard time int minutes; //minute value for standard time char AMorPM; //indicates day or night int militaryTime; //the military time }; //**************************************************************************** //* //* The main function //* //**************************************************************************** int main() { Time t; //Test 1 -- default constructor cout << endl << "Test 1: Default constructor" << endl; t.display(); //Test 2 -- setTime method cout << endl << endl << "Test 2: setTime method" << endl; t.setTime(1,29,'P'); t.display(); cout << endl; t.setTime(5,30,'P'); t.display(); cout << endl; t.setTime(15,15,'A'); t.display(); cout << endl; t.setTime(7,2,'A'); t.display(); cout << endl; t.setTime(1,64,'P'); t.display(); cout << endl; t.setTime(12,0,'P'); t.display(); cout << endl; t.setTime(1,23,'R'); t.display(); cout << endl; t.setTime(2,34,'A'); t.display(); //Test 3 -- toMilitary method cout << endl << endl << "Test 3: toMilitary method" << endl; cout << "5:42 AM is " << t.toMilitary(5,42,'A') << " in military time" << endl; cout << endl << "5:42 PM is " << t.toMilitary(5,42,'P') << " in military time" << endl; cout << endl << "12:00 AM is " << t.toMilitary(12,0,'A') << " in military time" << endl; cout << endl << "12:00 PM is " << t.toMilitary(12,0,'P') << " in military time" << endl; int hr, min; char p; //Test 4 -- toStandard method cout << endl << endl << "Test 4: toStandard method" << endl; t.toStandard(1720, hr, min, p); cout << "Military time 1720 is standard time hour = " << hr << " minute = " << min << " time of day = " << p << "M" << endl; t.toStandard(0, hr, min, p); cout << "Military time 0 is standard time hour = " << hr << " minute = " << min << " time of day = " << p << "M" << endl; t.toStandard(1200, hr, min, p); cout << "Military time 1200 is standard time hour = " << hr << " minute = " << min << " time of day = " << p << "M" << endl; //Test 5 -- second constructor cout << endl << endl << "Test 5: second constructor" << endl; Time t2(1,23,'A'); t2.display(); //Test 6 -- set Methods cout << endl << endl << "Test 6: set Methods" << endl; cout << "The current time is: "; t2.display(); t2.setHours(15); cout << endl << " After using an invalid hour the current time is: "; t2.display(); cout << endl << " After using a valid hour the current time is: "; t2.setHours(4); t2.display(); cout << endl; t2.setMinutes(-10); cout << endl << " After using an invalid minute the current time is: "; t2.display(); t2.setMinutes(10); cout << endl << " After using a valid minute the current time is: "; t2.display(); cout << endl; t2.setAMorPM('R'); cout << endl << " After using an invalid time of day the time is: "; t2.display(); t2.setAMorPM('P'); cout << endl << " After using a valid time of day the time is: "; t2.display(); cout << endl; t2.setMilitary(2400); cout << endl << " After using an invalid military time the time is: "; t2.display(); t2.setMilitary(1234); cout << endl << " After using a valid military time the time is: "; t2.display(); //Test 7 -- get Methods cout << endl << endl << "Test 7: get Methods" << endl; cout << "The current time in object t is: "; t.display(); cout << endl << " The hours value is " << t.getHours(); cout << endl << " The minute value is " << t.getMinutes(); cout << endl << " The time of day value is " << t.getAMorPM(); cout << endl << " The military time is " << t.getMilitary(); cout << endl << endl << "The current time in object t2 is: "; t2.display(); cout << endl << " The hours value is " << t2.getHours(); cout << endl << " The minute value is " << t2.getMinutes(); cout << endl << " The time of day value is " << t2.getAMorPM(); cout << endl << " The military time is " << t2.getMilitary(); cout << endl; system("pause"); return 0; } // end of main //**************************************************************************** //* //* Code your methods below this box //* //****************************************************************************



LinkBack URL
About LinkBacks


