thanks for the question, here are the 5 files you will be needing. Let me know for any changes or modifications. We have override the get_hours and get_minutes member functions
///////////////////////////////////////////////////////////////////////
/////////////////////////////// Clock.h///////////////////////////////
///////////////////////////////////////////////////////////////////////
#ifndef CLOCK_H
#define CLOCK_H
#include<string>
using std::string;
class Clock
{
public:
virtual int get_hours();
virtual int get_minutes();
virtual string get_time();
};
#endif
////////////////////////////////////////////////////////////////////////
/////////////////////////////// Clock.cpp///////////////////////////////
////////////////////////////////////////////////////////////////////////
#include "Clock.h"
#include<string>
#include<ctime>
#include<sstream>
using namespace std;
int Clock::get_hours() {
time_t current_time = time(0);
tm* local_time=localtime(¤t_time);
return local_time->tm_hour;
}
int Clock::get_minutes() {
time_t current_time = time(0);
tm* local_time=localtime(¤t_time);
return local_time->tm_min;
}
string Clock::get_time() {
int hours = get_hours();
int minutes = get_minutes();
if(hours>12){
stringstream ss;
ss<<(hours-12)<<":"<<minutes;
string time;
ss>>time;
return time+" PM";
}else{
stringstream ss;
ss<<(hours)<<":"<<minutes;
string time;
ss>>time;
return time+" AM";
}
}
///////////////////////////////////////////////////////////////////////////
/////////////////////////////// WorldClock.h///////////////////////////////
///////////////////////////////////////////////////////////////////////////
#ifndef WORLDCLOCK_H
#define WORLDCLOCK_H
#include "Clock.h"
class WorldClock:public Clock
{
public:
WorldClock(int);
int get_hours();
int get_minutes();
private:
int ahead;
};
#endif
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////// WorldClock.cpp///////////////////////////////
/////////////////////////////////////////////////////////////////////////////
#include "WorldClock.h"
#include<string>
#include<ctime>
#include<sstream>
using namespace std;
WorldClock::WorldClock(int ahead):Clock(), ahead{ahead}{
}
int WorldClock::get_hours(){
time_t current_time = time(0);
tm* local_time=localtime(¤t_time);
int hours= local_time->tm_hour;
int minutes = local_time->tm_min;
int total_minutes = hours*60+minutes + ahead*30;
total_minutes%=24*60;
return total_minutes/60;
}
int WorldClock::get_minutes(){
time_t current_time = time(0);
tm* local_time=localtime(¤t_time);
int hours= local_time->tm_hour;
int minutes = local_time->tm_min;
int total_minutes = hours*60+minutes + ahead*30;
total_minutes%=24*60;
return total_minutes%60;
}
///////////////////////////////////////////////////////////////////////
/////////////////////////////// main.cpp///////////////////////////////
///////////////////////////////////////////////////////////////////////
#include <iostream>
#include "Clock.h"
#include "WorldClock.h"
using namespace std;
int main(){
Clock clock;
cout<<"New York Time: "<<clock.get_time()<<endl;
WorldClock worldClock(3);
cout<<"London Time: "<<worldClock.get_time()<<endl;
}
///////////////////////////////////////////////////////////////////////
Use c++ to code: Problem 1 Implement a class Clock whose get hours and get_minutes member functions return the current...
Problem 1.(1) Implement a class Clock whose getHours and getMinutes methods return the current time at your location. (Call java.time.LocalTime.now().toString() or, if you are not using Java 8, new java.util.Date().toString() and extract the time from that string.) Also provide a getTime method that returns a string with the hours and minutes by calling the getHours and getMinutesmethods. (2) Provide a subclass WorldClock whose constructor accepts a time offset. For example, if you live in California, a new WorldClock(3) should show...
JAVA PROGRAM. Write a program to implement a class Clock whose getHours and getMinutes methods return the current time at your location. Also include a getTime method that returns a string with the hours and minutes by calling the getHours and getMinutes methods. Provide a subclass WorldClock whose constructor accepts a time offset. For example, if you livein California, a new WorldCLock(3) should show the time in NewYork, three time zones ahead. Include an Alarm feature in the Clock class....
I need help implementing class string functions, any help would be appreciated, also any comments throughout would also be extremely helpful. Time.cpp file - #include "Time.h" #include <new> #include <string> #include <iostream> // The class name is Time. This defines a class for keeping time in hours, minutes, and AM/PM indicator. // You should create 3 private member variables for this class. An integer variable for the hours, // an integer variable for the minutes, and a char variable for...
1. (40’) In myStack.cpp, implement the member functions of the class myStack, which is the class for integer stacks. 2. (20’) In stackTest.cpp, complete the implementation of function postfixTest(), which use an integer stack to evaluate post-fix expressions. For simplicity, you can assume the post-fix expression is input character by character (i.e., not an entire string), and each operand is a non-negative, single-digit integer (i.e., 0,1,…,9). However, you are supposed to detect invalid/ illegal post-fix expression input, e.g., “4 5...
For this project you will be writing up a simple Clock program to keep track of time. SimpleClock.java - contains your implementation of the SimpleClock class. You will need to provide the code for a constructor as well as the mutator methods set and tick and the accessor method toString. Look at the comments for each method to see how they should be implemented - the trickiest method is probably tick, which requires that you deal with the changing of...
Objectives You will implement and test a class called MyString. Each MyString object keeps track of a sequence of characters, similar to the standard C++ string class but with fewer operations. The objectives of this programming assignment are as follows. Ensure that you can write a class that uses dynamic memory to store a sequence whose length is unspecified. (Keep in mind that if you were actually writing a program that needs a string, you would use the C++ standard...
1. Implement a tostring() member function. This function will return a string representation of the LargeInteger. You should probably used string streams to implement this function. Note that the digits of the large integer are stored in reverse of their display order, e.g. the 1's place (100 ) is in index 0 of digits, the 10's place (101 ) is in index 1, etc. 2. Implement a second constructor for the LargeInteger. This constructor will be used to construct a...
An array of class objects is similar to an array of some other data type. To create an array of Points, we write Point parray [4]; To access the object at position i of the array, we write parray [i] and to call a method on that object method, we write parray [i]. methodName (arg1 , arg2 , ...) ; To initialize an array of objects whose values are known at compile time, we can write Point parray [4] =...
For C++
This is the information about the meal class
2-1. (24 marks) Define and implement a class named Dessert, which represents a special kind of Meal. It is to be defined by inheriting from the Meal class. The Dessert class has the following constructor: Dessert (string n, int co) // creates a meal with name n, whose type // is "dessert" and cost is co The class must have a private static attribute static int nextID ; which is...
C++ Linked List Implementation Motivation As we discussed in class, the data structures that you use to implement your program can have a profound impact on it's overall performance. A poorly written program will often need much more RAM and CPU time then a well-written implementation. One of the most basic data structure questions revolves around the difference between an array and a linked list. After you finish this assignment you should have a firm understanding of their operation. Problem...