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) 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,...
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...
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...
The following program will be written in JAVA. Create a class called complex performing arithmetic with...
The following program will be written in JAVA. Create a class called complex performing arithmetic with complex numbers. Write a program to test your class.                         Complex numbers have the form:                         realPart + imaginaryPart * i                                               ___                         Where i is sqrt(-1)                                                 Use double variables to represent data of the class. Provide a constructor that enables an object of this class to be initialized when it is declared. The constructor should contain default values in...
JAVA Homework 1) Create a die class. This is similar to the coin class , but...
JAVA Homework 1) Create a die class. This is similar to the coin class , but instead of face having value 0 or 1, it now has value 1,2,3,4,5, or 6. Also instead of having a method called flip, name it roll (you flip a coin but roll a die). You will NOT have a method called isHeads, but you will need a method (call it getFace ) which returns the face value of the die. Altogether you will have...
1. Create a console program in C#, * Create a class: "Student.cs" * Add 3 variables:...
1. Create a console program in C#, * Create a class: "Student.cs" * Add 3 variables: StudentName (string), SchoolYear (int), YearsUntilGraduation(int) * Method YTK() = 12 - SchoolYear; 2. Main *Enter name *Enter age *You will attend school:____ years before graduating.
(In C++) Bank Account Program Create an Account Class Create a Menu Class Create a main()...
(In C++) Bank Account Program Create an Account Class Create a Menu Class Create a main() function to coordinate the execution of the program. We will need methods: Method for Depositing values into the account. What type of method will it be? Method for Withdrawing values from the account. What type of method will it be? Method to output the balance of the account. What type of method will it be? Method that will output all deposits made to the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT