In this lab, we will implement a simple C++ class named Time. It represents all possible times in a 24-hour period, including hours, minutes and seconds. An immediate representation issue is how to handle morning (am) and afternoon (pm) times. We could have a separate bool indicating whether the time is am or pm. It is easier, however, to represent the hours in military time. This means that the hours of the day are numbered from 0 to 23, with 13 being 1 pm, 14 being 2 pm, etc. Your notes from Lecture 3 with the example Date class will be helpful in completing this lab. Checkpoint 1 In the rst checkpoint you will get started by implementing the initial class design, several member functions, and a simple main program to test your class. The instructions below describe how to build your executable using from the command line using g++ or clang++ using Cygwin or UNIX terminal. Even if you plan to use Visual Studio or another IDE for the bulk of your work this semester, you are required to also show that you can successfully build and run this lab using g++ from a terminal on your own machine. Make a subfolder inside of your Data Structures labs directory for lab 2. Create 3 new empty code les named time.h, time.cpp and main.cpp. Note that in C++ the name of the header and implementation le are not required to exactly match the name of the class, but it is good coding style to do so. Begin work on time.h. Within the le, declare a class called Time. Follow the form and syntax of the Date class from Lecture 3. Read the syntax carefully (such as the semi-colon at the end of the class declaration). Add private member variables for the hour, minute and second. In the public area of the class, declare two constructors: one, the default constructor, should initialize each of the member variables to 0; the other, having three arguments, accepts initial values for the hour, minute and second as function call arguments. Declare member functions to access the values of the hour, the minute and the second (three dierent member functions). It will be crucial for Checkpoint 3 to make these const. (Recall: a const member function can not change the member variables.) Dont write the body of any of the functions in the time.h le. Save all the implementation for the time.cpp le. Switch to working on main.cpp. Be sure to add code to #include time.h in addition to including #include
Programming
[Solved] SOLVED:Lab 2 C++ Classes soln
$25
File Name: SOLVED:Lab_2__C++_Classes_soln.zip
File Size: 282.6 KB
Only logged in customers who have purchased this product may leave a review.
Reviews
There are no reviews yet.