Answer to Question #217141 in C++ for scott

Question #217141

The science museum has asked you to write a c++ application that children can use to find the total number of hours and years slept during their lifetime. Assume they slept at an average of 8 hour per night. The user should enter the name, birthday, year and current year.

Name - Mercy

day - 01

year - 1999

Current year - 2021


To calculate the number of hours slept. Assume 365 day per year, 30 day per month and 8 hours of sleep per day. The program should show how many years, month, weeks, days, hours, minutes, seconds the child slept in this lifetime.

Note : use classes, function, and control structures to achieve this task. the user will also determine the number of children the process.


1
Expert's answer
2021-07-14T07:33:01-0400
#include<iostream>
using namespace std;
class museum{
	private:
	 string name;
	 int  birthday, year,  current_year;
	public:
		museum(){
			
		}
		museum(string n, int b, int y, int c){
			name = n;
			birthday = b;
			year = y;
			current_year = c;
		}
		int childrenNumber(){
			int n; 
			cout<<"Enter the number of children to processs\n";
			cin>>n;
			return n;
		}
		string getName(){
			return name;
		}
		int getBirth(){
			return birthday;
		}
		int getYear(){
			return year;
		}
		int getCurrent(){
			return current_year;
		}
		int totalDays(){ //365 days is equal to 1 year
			return (current_year - year) * 365;
		}
		int totalHourSlept(){
			return totalDays() * 8;
		}
		int totalDaySlept(){
			return totalHourSlept() / 24;
		}
			int totalMonthSlept(){
			return totalHourSlept() / 30;
		}
		
		
		int totalYearsSlept(){
			return totalHourSlept() / 8760;
		}
		int totalMinutesSlept(){
			totalHourSlept() * 60;
		}
		int totalSecondSlept(){
			totalHourSlept() * 60 *60 ;
		}
		void totaltime(){
			cout<<"The name of the child is:\t "<<name<<endl;
			cout<<"Years:\t"<<totalYearsSlept()<<endl;
			cout<<"Month:\t"<<totalMonthSlept()<<endl;
				cout<<"Days:\t"<<totalDaySlept()<<endl;
				cout<<"Hours:\t"<<totalHourSlept()<<endl;
					cout<<"Minutes:\t"<<totalMinutesSlept()<<endl;\
				cout<<"Seconds:\t"<<totalSecondSlept()<<endl;
		}
};
int main(){
	
	museum t;
	int n = t.childrenNumber();
	for(int i=0; i<n; i++){
	string name;
	 int  birthday, year,  current_year;
	 cout<<"The child name\n"<<endl;
	 cin>>name;
	 cout<<"The child birhtday\n"<<endl;
	 cin>>birthday;
	 cout<<"The child year born \n"<<endl;
	 cin>>year;
	 cout<<"The current year\n"<<endl;
	 cin>>current_year;
	 	museum t1(  name, birthday, year, current_year);
	 	t1.totaltime();
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS