======================== c++ code of the time class with given specification =============
#include <iostream>
#include<iomanip>
using namespace std;
class Time //class representing time
{
private :
int hour;
int minute;
int second;
public :
// default constructor with default value
Time(int h = 0, int m = 0, int s = 0);
//input function
void inputTime(int h, int m, int s);
//display time in hh:mm:ss
void display();
//check equality of 0 or 1 two time object
bool compare(Time);
void incrementBy1Second(); // incrementBy1Second
void incrementBy1Minute();// incrementBy1Minute
void incrementBy1hour();// incrementBy1hour
};
Time :: Time(int h, int m, int s)
{
hour = h;
minute = m;
second = s;
}
void Time :: inputTime(int h, int m, int s)
{
hour = h;
minute = m;
second = s;
}
void Time :: display()
{
cout << setw(2) << setfill('0') << hour <<
":"
<< setw(2) << setfill('0') << minute <<
":"
<< setw(2) << setfill('0') << second <<
"\n";
}
bool Time :: compare(Time otherTime)
{
if(hour == otherTime.hour &&
minute == otherTime.minute &&
second == otherTime.second)
return true;
else
return false;
}
void Time :: incrementBy1Second()
{
if(second<60)
{
second+=1;
}
else if(second==60)
{
if(minute<60)
{
minute+=1;
second=0;
}
else if(minute==60)
{
if(hour<24)
{
hour+=1;
minute=0;
second=0;
}
else if(hour==24)
{
hour = 0;
minute=0;
second=0;
}
}
}
}
void Time :: incrementBy1Minute()
{
if(minute<60)
{
minute+=1;
}
else if(minute==60)
{
if(hour<23)
{
hour+=1;
minute=0;
}
else if(hour==23)
{
hour=0;
minute=0;
}
}
}
void Time :: incrementBy1hour()
{
if(hour<23)
{
hour+=1;
}
else
{
hour=0;
}
}
int main()
{
Time t[4];
t[0].inputTime(0,20,60);
t[1].inputTime(23,59,59);
t[2].inputTime(10,10,10);
t[3].inputTime(0,0,0);
t[0].incrementBy1Second();
t[1].incrementBy1Minute();
t[1].incrementBy1hour();
t[2].incrementBy1hour();
t[3].incrementBy1hour();
t[3].incrementBy1Minute();
t[4].incrementBy1Second();
t[0].display();
t[1].display();
t[2].display();
t[3].display();
bool result = t[1].compare(t[0]);
cout<<"result of comapre"<<result;
return 0;
}
========================== end of the code===================================================
Screenshots of the code and output:
============================================================================================
==============================================================================================--------------------------- Please like the post -------------------------
C++. here is the problem that kind of the same with the example that i did...
C++ Programming Step 1. Design a new ADT that implements a class named Date, add 3 private member variables month, day, year along with their appropriate public constructor / getter / setter member functions inside Date.h and Date.cpp. Step 2. Design another ADT that implements a class named Watch, add 3 private member variables hour, minute, second, along with their appropriate public constructor / getter / setter member functions inside Watch.h and Watch.cpp. Step 3. Next, implement the additional SmartWatch...
Need help with the flow chart of this program #include #include using namespace std; string months[] = {"January","February ","March","April","May","June","July","August","September","October","November","December"}; int days_in_months[] = {31,28,31,30,31,30,31,31,30,31,30,31}; class Date //Sample Class for the C++ Tutorial { private: int month; //Data member int day; // Data member int year; public: Date(int m, int d, int y) { if(m<1 || m >12) month = 1; else month = m; if(d<1 || d >days_in_months[month-1]) day = 1; else day = d; if(y<2001) year = 2001; else year...
Assuming that a year has 365 days, write a class named DayOfYear that takes an integer representing a day of the year and translates it to a string consisting of the month followed by day of the month. For example, Day 2 would be January 2. Day 32 would be February 1. Day 365 would be December 31. The constructor for the class should take as parameter an integer representing the day of the year, and the class should have...
-can you change the program that I attached to make 3 file songmain.cpp , song.cpp , and song.h -I attached my program and the example out put. -Must use Cstring not string -Use strcpy - use strcpy when you use Cstring: instead of this->name=name .... use strcpy ( this->name, name) - the readdata, printalltasks, printtasksindaterange, complitetasks, addtasks must be in the Taskmain.cpp - I also attached some requirements below as a picture #include <iostream> #include <iomanip> #include <cstring> #include <fstream>...
Write output of following program in C# afterremoving error if any. Note: Be sum of first two digit of your Roll no. Run the code after entering the value of B. Do not show error because of B. #include <iostream> using namespace std; class stud { public: char name[30.clas[10]; int rolage: void enter() { cout<<"Enter Student Name: "; cin>>name; cout<<"Enter Student Age: "; cin>>age; cout<<"Enter Student Roll number: "; cin>>rol; cout<<"Enter Student Class Year: "; cin>>clas; } void display {...
61. The following program is accepted by the compiler: int sum( int x, int y ) { int result; result = x + y; } T__ F__ 62. The following implementation is accepted by the compiler: void product() { int a; int b; int c; int result; cout << "Enter three integers: "; cin >> a >> b >> c; result = a * b * c; ...
#include#includeusing namespace std;// Implement printArray here// Implement deleteSmallest here// DO NOT CHANGE MAIN FUNCTION BELOWint main() {int myarray[100];cout << "Enter number of integers : ";int n;cin >> n;cout << "Enter " << n << " integers" << endl;for (int i = 0; i < n; i++)cin >> myarray[i];cout << "Contents of array : ";printArray(myarray, n);deleteSmallest(myarray, n);cout << "Contents of array after deleteSmallest: ";printArray(myarray, n-1);}
I'm kind of new to programming, and I am having trouble figuring out why my program isn't running. Below is the code that I wrote for practice. I will comment where it says the error is. So the error that I'm getting is "error: no match for 'operator>>' (operand types are 'std::istream {aka std::basic_istream<char>}' ". I'm not sure why I'm getting this because I added the library <iostream> at the top. Thank you. Code: #include <iostream> using namespace std; class...
In C++ Consider the following Date class: #include <iostream> using namespace std; class MyDate { private: int month, day, year; public: MyDate() {setDate(2,27,2006);} MyDate(int, int, int); void setDate(int mm, int dd, int yyyy); void showDate(); }; MyDate::MyDate(int mm, int dd, int yyyy) { month = mm; day = dd; year = yyyy; }; void MyDate::setDate(int mm, int dd, int yyyy) { month = mm; day = dd; year = yyyy; }; void MyDate::showDate() { cout << "The date is "...
2 The following code has some errors. Please point out and correct them (there might be more than 1 errors). Note: the use of const data member increment and member function print. // This code has some errors. #include using namespace std; class Increment { public: Increment( int c = 0, int i = 0); void addIncrement() const { count -= increment }; void print() const; private: int count; const int increment; }; Increment::Increment(int c, int i) { cout =...