On Dev C++ Using the header file provided below "myClock.h", implement a C++ program that present the user with the following menu: "Press 1 to read the time." "Press 2 to enter a new time." "Press 3 to exit." -------------------------------------------------------------- Submit both file, myClock.h and your implementation .cpp myClock.h class myClock { public: myClock(); ~myClock(){}; void setTime(int, int, int); // Add the getter function prototype here . private: int hour; int minute; int second; };
#ifndef CCC_TIME_H
#define CCC_TIME_H
// Defines class myClock to store time
class myClock
{
public:
// Prototype of member functions
myClock();
~myClock(){};
void setTime(int, int, int);
void setHour(int);
void setMinute(int);
void setSecond(int);
int getHour();
int getMinute();
int getSecond();
private:
// Data member to store data
int hour; int minute; int second;
};// End of class
#endif
------------------------------------------------------------------------------------------------
#include "MyClock.h"
// Default constructor to assign default value to data
member
myClock::myClock()
{
hour = minute = second = 0;
}// End of default constructor
// Function to assign parameter values to data member
void myClock::setTime(int h, int m, int s)
{
hour = h;
minute = m;
second = s;
}// End of function
// Function to set hour
void myClock::setHour(int h)
{
hour = h;
}// End of function
// Function to set minute
void myClock::setMinute(int m)
{
minute = m;
}// End of function
// Function to set second
void myClock::setSecond(int s)
{
second = s;
}// End of function
// Function to return hour
int myClock::getHour()
{
return hour;
}// End of function
// Function to return minute
int myClock::getMinute()
{
return minute;
}// End of function
// Function to return second
int myClock::getSecond()
{
return second;
}// End of function
------------------------------------------------------------------------------------------------
#include "MyClock.cpp"
#include <iostream>
#include <cstdlib>
#include <fstream>
#define MAX 100
using namespace std;
// Function to display menu, accept user choice and returns user choice
int menu()
{
// To store user choice
int ch;
// Displays menu
cout<<"\n\n ****************** MENU ****************** ";
cout<<"\n Press 1 to read the time.";
cout<<"\n Press 2 to enter a new time.";
cout<<"\n Press 3 to display times.";
cout<<"\n Press 4 to exit.";
// Accepts user choice
cout<<"\n Select >> ";
cin>>ch;
// Returns user choice
return ch;
}// End of function
// Function to read file contents and stores it in array of object mc
// Returns number of records using pass by reference
void readFile(myClock mc[], int &len)
{
// ifstream object declared
ifstream fRead;
// To store hour, minute, and second read from file
int h, m, s;
// Opens the file for reading
fRead.open("MyTime.txt");
// Checks if the file unable to open for reading display's error message and stop
if(!fRead)
{
cout<<"\n ERROR: Unable to open the file for reading.";
exit(0);
}// End of if condition
// Loops till end of the file
while(!fRead.eof())
{
// Reads hour, minute and second from file
fRead>>h;
fRead>>m;
fRead>>s;
// Calls the function to set hour, minute and second at len index position
mc[len].setMinute(m);
mc[len].setHour(h);
mc[len].setSecond(s);
// Increase the record counter by one
len++;
}// End of while loop
// Displays number of records read
cout<<"\n Read "<<len<<" records successfully.";
}// End of function
// Function to accept time and assigns it to array of object mc
void enterTime(myClock mc[], int &len)
{
// To store hour, minute, and second read from file
int h, m, s;
// Accepts hour, minute and second from user
cout<<"\n Enter hour: ";
cin>>h;
cout<<"\n Enter minute: ";
cin>>m;
cout<<"\n Enter second: ";
cin>>s;
// Calls the function to set hour, minute and second at len index position
mc[len].setTime(h, m, s);
// Increase the record counter by one
len++;
cout<<"\n Record added successfully.";
}// End of function
// Function to display all the times
void showTime(myClock mc[], int len)
{
// Loops till number of records
for(int c = 0; c < len; c++)
// Displays each time
cout<<"\n\n Time "<<(c + 1)<<" => "<<mc[c].getHour()<<":"<<mc[c].getMinute()<<":"<<mc[c].getSecond();
}// End of function
// main function definition
int main()
{
// Declares an array of object of class myClock of size MAX
myClock mc[MAX];
// Record counter
int len = 0;
// Loops till user choice is not 4
do
{
// Calls the function to accept user choice
// calls the function based on user choice
switch(menu())
{
case 1:
readFile(mc, len);
break;
case 2:
enterTime(mc, len);
break;
case 3:
// Checks if len is 0 then there is no record to display
if(len == 0)
cout<<"\n Empty Time List. \n There is no record to display.";
// Otherwise calls the function to display times
else
showTime(mc, len);
break;
case 4:
exit(0);
default:
cout<<"\n Invalid choice........";
}// End of switch - case
}while(1);// End of do - while loop
}// End of man function
Sample Output:
****************** MENU ******************
Press 1 to read the time.
Press 2 to enter a new time.
Press 3 to display times.
Press 4 to exit.
Select >> 3
Empty Time List.
There is no record to display.
****************** MENU ******************
Press 1 to read the time.
Press 2 to enter a new time.
Press 3 to display times.
Press 4 to exit.
Select >> 1
Read 6 records successfully.
****************** MENU ******************
Press 1 to read the time.
Press 2 to enter a new time.
Press 3 to display times.
Press 4 to exit.
Select >> 3
Time 1 => 10:2:23
Time 2 => 12:5:33
Time 3 => 2:55:3
Time 4 => 11:56:55
Time 5 => 7:8:23
Time 6 => 7:8:23
****************** MENU ******************
Press 1 to read the time.
Press 2 to enter a new time.
Press 3 to display times.
Press 4 to exit.
Select >> 2
Enter hour: 11
Enter minute: 22
Enter second: 33
Record added successfully.
****************** MENU ******************
Press 1 to read the time.
Press 2 to enter a new time.
Press 3 to display times.
Press 4 to exit.
Select >> 3
Time 1 => 10:2:23
Time 2 => 12:5:33
Time 3 => 2:55:3
Time 4 => 11:56:55
Time 5 => 7:8:23
Time 6 => 7:8:23
Time 7 => 11:22:33
****************** MENU ******************
Press 1 to read the time.
Press 2 to enter a new time.
Press 3 to display times.
Press 4 to exit.
Select >> 4
On Dev C++ Using the header file provided below "myClock.h", implement a C++ program that present...
Write a C++ program to implement Queue ADT using singly linked structure. The program includes the following: Define the Queue class template in the header file QueueLinked.h. // QueueLinked.h #ifndef QUEUE_H #define QUEUE_H #include <iostream> using namespace std; template <typename T> class Queue { public: // Constructor Queue(); //Desctructor ~Queue(); // Makes the queue to the empty state. void make_empty(); // Checks if the queue is empty. bool empty() const; // Inserts item at the end of the queue. void...
I am working in c++. My program requires me to use a header file that is provided. I must use this header file and create 5 methods: 2 constructors, 2 accessors and this operation* on a 4x4 matrix. Matrix has 16 floating point values that must be entered by user. The Two operator functions: i*t; and t+i, multiply identity (i) matrix by user input value matrix and second function add identity (i) plus user input matrix transform. These two operations...
C++ project we need to create a class for Book and Warehouse
using Book.h and Warehouse.h header files given. Then make a main
program using Book and Warehouse to read data from book.dat and
have functions to list and find book by isbn
Objectives: Class Association and operator overloading This project is a continuation from Project 1. The program should accept the same input data file and support the same list and find operations. You will change the implementation of...
2. In the following program an employee of a company is represented by an object of type employee consisting of a name, employee id, employee salary and the workday starting time. The starting time is a class time 24 object. Implement the class employee. Declaration of Employee and Time Classes /* File : employeetime.h Hlustrates composition of classes */ #ifndef EMPLOYEETIME.H #define EMPLOYEETIME.H #include <iostream> #include <string> using namespace std; class time 24 { private : int hour; int minute...
Refer to this header file: // Fraction class // This class represents a fraction a / b class Fraction { public: // Constructors Fraction(); // sets numerator to 1 and denominator to 1 Fraction(int num, int denom); // Setters void setNumerator(int num); void setDenominator(int denom); // getters int getNumerator()const {return num;} int getDenominator()const {return denom;} double getDecimal(){return static_cast<double> num / denom;} private: int num, denom; }; 1.Write the code for the non-member overloaded << operator that will display all of...
Using the following definition (List.h file) for a list, implement the member functions (methods) for the List class and store the implementation in a List.cpp file. Use a doubly linked list to implement the list. Write the client code (the main method and other non-class methods) and put in file driver.cpp. file: List.h typedef int ElementType; class node{ ElementType data; node * next; node* prev; }; class List { public: List(); //Create an empty list bool Empty(); // return true...
Write a C++ program that includes the following: Define the class Student in the header file Student.h. #ifndef STUDENT_H #define STUDENT_H #include <string> #include <iostream> using namespace std; class Student { public: // Default constructor Student() { } // Creates a student with the specified id and name. Student(int id, const string& name) { } // Returns the student name. string get_name() const { } // Returns the student id. int get_id () const { } // Sets the student...
Please help with Java programming!
This code is to implement a Clock class.
Use my beginning code below to test your
implementation.
public class Clock {
// Declare your fields here
/**
* The constructor builds a Clock object and sets time to
00:00
* and the alarm to 00:00, also.
*
*/
public Clock() {
setHr(0);
setMin(0);
setAlarmHr(0);
setAlarmMin(0);
}
/**
* setHr() will validate and set the value of the hr field
* for the clock.
*
*...
Write a C++ Program. You have a following class as a header file (dayType.h) and main(). #ifndef H_dayType #define H_dayType #include <string> using namespace std; class dayType { public: static string weekDays[7]; void print() const; string nextDay() const; string prevDay() const; void addDay(int nDays); void setDay(string d); string getDay() const; dayType(); dayType(string d); private: string weekDay; }; #endif /* // Name: Your Name // ID: Your ID */ #include <iostream>...
Java Programming
The program template represents a complete working Java program
with one or more key lines of code replaced with comments. Read the
problem description and examine the output, then study the template
code. Using the problem-solving tips as a guide, replace the /* */
comments with Java code. Compile and execute the program. Compare
your output with the sample output provided. Modify class Time2 to
include a tick method that increments the time stored in a Time2
object...