Question

In: Computer Science

C++ program homework question 1 1. Create and implement a class called clockType with the following...

C++ program homework question 1

1. Create and implement a class called clockType with the following data and methods (60 Points.):

  • Data:
    • Hours, minutes, seconds
  • Methods:
    • Set and get hours
    • Set and get minutes
    • Set and get seconds
    • printTime(…) to display time in the form of hh:mm:ss
    • default and overloading constructor
  1. Overloading Operators:
    • << (extraction) operator to display time in the form of hh:mm:ss
    • >> (insertion) operator to get input for hours, minutes, and seconds
    • operator+=(int x) (increment operator) to increment by x seconds
    • operator<=(…) which returns true if time of the clock is less than or equal to another clock
    • operator>=(…) which returns true if time of the clock is greater than or equal to another clock

Derive a new class called extClockType from the class clockType by adding a member variable to store the time zone. Add the necessary member functions and constructors and implement them

Solutions

Expert Solution

Please find the code , output below.

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
// Class declaration
class clockType {
  
public:
int hours, minutes, seconds;
clockType (int hours1, int minutes1, int seconds1){
hours=hours1;
minutes=minutes1;
seconds=seconds1;
}
void sethours(int hours1){
hours=hours1;
}
void setminutes(int minutes1){
minutes=minutes1;
}
void setseconds(int seconds1){
seconds=seconds1;
}
int gethouors(){
return hours;
}
int getminutes(){
return minutes;
}
int getseconds(){
return seconds;
}
// Printing the output
void printTime(){
if(hours<10 && minutes>=10 && seconds >=10){
cout<<"The time is 0"<<hours<<" : "<< minutes<< " : "<<seconds<<endl;
}
else if (hours>=10 && minutes < 10 && seconds>=10){
cout<<"The time is "<<hours<<" : 0"<< minutes<< " : "<<seconds<<endl;
}
else if (hours>=10 && minutes >= 10 && seconds <10){
cout<<"The time is "<<hours<<" : "<< minutes<< " : 0"<<seconds<<endl;
}
else if (hours>=10 && minutes < 10 && seconds <10){
cout<<"The time is "<<hours<<" : 0"<< minutes<< " : 0"<<seconds<<endl;
}
else if (hours <10 && minutes >= 10 && seconds <10){
cout<<"The time is 0"<<hours<<" : "<< minutes<< " : 0"<<seconds<<endl;
}
else if (hours <10 && minutes < 10 && seconds >=10){
cout<<"The time is 0"<<hours<<" : 0"<< minutes<< " : "<<seconds<<endl;
}
else if (hours<10 && minutes < 10 && seconds <10){
cout<<"The time is 0"<<hours<<" : 0"<< minutes<< " : 0"<<seconds<<endl;
}
else{
cout<<"The time is "<<hours<<" : "<< minutes<< " : "<<seconds<<endl;
}
}
};
// Child class
class extClockType : public clockType {
public:
vector<string> time_zone;
extClockType(int hours1, int minutes1, int seconds1,string timezone): clockType(hours1,minutes1,seconds1){
time_zone.push_back(timezone);
}
void printTimezone(){
cout<<"\nThe timezone is "<<time_zone[0];
}
};

int main()
{   
// Getting input from user
int hours, minutes, seconds;
cout<<"Enter the hours : ";
cin>>hours;
if(hours<0 || hours>24){
cout<< "Invalid hours !!!";
exit(0);
}
cout<<"Enter the minutes : ";
cin>>minutes;
if(minutes<0 || minutes>60){
cout<< "Invalid minutes !!!";
exit(0);
}
cout<<"Enter the seconds : ";
cin>>seconds;
if(seconds<0 || seconds>60){
cout<< "Invalid seconds !!!";
exit(0);
}
// Creating object of clockType class
clockType ct(hours,minutes,seconds);
  
//ct.printTime();
extClockType ect(hours,minutes,seconds,"Pacific");
// Calling the function
ect.printTime();
ect.printTimezone();
return 0;
}


Related Solutions

1. create a class called ArrayStack that is a generic class. Create a main program to...
1. create a class called ArrayStack that is a generic class. Create a main program to read in one input file and print out the file in reverse order by pushing each item on the stack and popping each item off to print it. The two input files are: tinyTale.txt and numbers.txt. Rules: You cannot inherit the StackofStrings class. 2. Using your new ArrayStack, create a new class called RArrayStack. To do this, you need a) remove the capacity parameter...
1. create a class called ArrayStack that is a generic class. Create a main program to...
1. create a class called ArrayStack that is a generic class. Create a main program to read in one input file and print out the file in reverse order by pushing each item on the stack and popping each item off to print it. The two input files are: tinyTale.txt and numbers.txt. Rules: You cannot inherit the StackofStrings class. 2. Using your new ArrayStack, create a new class called RArrayStack. To do this, you need a) remove the capacity parameter...
Please use C++ to complete this question follow the requirement. Question: Implement a class called DoublyLinkedList....
Please use C++ to complete this question follow the requirement. Question: Implement a class called DoublyLinkedList. In the main function, instantiate the DoublyLinkedList class and make sure that there is a user loop and a menu so that the user can access all the list operators. You should implement the following operators, and any others that you may deem best. DestroyList InitializeList GetFirst InsertFirst, InsertLast, Insert DeleteFirst, DeleteLast, Delete IsEmpty Length Print, ReversePrint
Separate code into .cpp and .h files: // C++ program to create and implement Poly class...
Separate code into .cpp and .h files: // C++ program to create and implement Poly class representing Polynomials #include <iostream> #include <cmath> using namespace std; class Poly { private: int degree; int *coefficients; public: Poly(); Poly(int coeff, int degree); Poly(int coeff); Poly(const Poly& p); ~Poly(); void resize(int new_degree); void setCoefficient(int exp, int coeff); int getCoefficient(int exp); void display(); }; // default constructor to create a polynomial with constant 0 Poly::Poly() { // set degree to 0 degree = 0; //...
1) Design an implement a program that created and exception class called StringTooLongException, designed to be...
1) Design an implement a program that created and exception class called StringTooLongException, designed to be thrown when a string is discovered that has too many characters in it. Create a driver that reads in strings from the user until the user enters DONE. If a string that has more then 5 characters is entered, throw the exception. Allow the thrown exception to terminate the program 2) Create a class called TestScore that has a constructor that accepts an array...
Program in Java Create a stack class to store integers and implement following methods: 1- void...
Program in Java Create a stack class to store integers and implement following methods: 1- void push(int num): This method will push an integer to the top of the stack. 2- int pop(): This method will return the value stored in the top of the stack. If the stack is empty this method will return -1. 3- void display(): This method will display all numbers in the stack from top to bottom (First item displayed will be the top value)....
Program in Java Create a queue class to store integers and implement following methods: 1- void...
Program in Java Create a queue class to store integers and implement following methods: 1- void enqueue(int num): This method will add an integer to the queue (end of the queue). 2- int dequeue(): This method will return the first item in the queue (First In First Out). 3- void display(): This method will display all items in the queue (First item will be displayed first). 4- Boolean isEmpty(): This method will check the queue and if it is empty,...
JAVA PROGRAM Question : Design and implement two classes called InfixToPostfix and PostFixCalculator. The InfixToPrefix class...
JAVA PROGRAM Question : Design and implement two classes called InfixToPostfix and PostFixCalculator. The InfixToPrefix class converts an infix expression to a postfix expression. The PostFixCalculator class evaluates a postfix expression. This means that the expressions will have already been converted into correct postfix form. Write a main method that prompts the user to enter an expression in the infix form, converts it into postfix, displays the postfix expression as well as it's evaluation. For simplicity, use only these operators,...
C++ Question1. Create a class called Rantional for performing arithmatic with fractions. Then write a program...
C++ Question1. Create a class called Rantional for performing arithmatic with fractions. Then write a program to test your class. Use integer variables to represent the private data of the class, meaning the numerator and the denominator. Provide a constructor that enables an object of this class to be initialized when it's declared. The constructor should contain default values in case no initializers are provided and should store the fraction in reduced form. For example fraction 2/4 would be stored...
Program in Java Create a class and name it MyArray and implement following method. * NOTE:...
Program in Java Create a class and name it MyArray and implement following method. * NOTE: if you need more methods, including insert(), display(), etc. you can also implement those. Method name: getKthMin(int k) This method receives an integer k and returns k-th minimum value stored in the array. * NOTE: Items in the array are not sorted. If you need to sort them, you can implement any desired sorting algorithm (Do not use Java's default sorting methods). Example: Items...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT