2 You are an electrical engineer performing tests on electri

2. You are an electrical engineer performing tests on electric car batteries. You need to know how long the experiment has been running in seconds. For the purposes of this assignment, make an assumption that a month is 30 days and a year is 365 days • In the script file, perform the following tasks: Prompt the user to input how many complete years ago the experiment started. Prompt the user to input how many complete months ago the experiment started. Prompt the user to input how many complete days ago the experiment started. Prompt the user to input how many complete hours ago the experiment started. Prompt the user to input how many complete minutes ago the experiment started. Prompt the user to input how many additional seconds ago the experiment started. Convert the time to be all in seconds. Print to the screen a complete sentence saying how many years, months, days, hours, minutes, and seconds ago the experiment was started. These should all be positive integers. Print to the screen a sentence with the equivalent total number of seconds ago the experiment was started. This should be a positive integer. Calculate the equivalent number of hours the total amount of time is. Print to the screen a sentence with the number of hours. Display the answer with exactly three decimal places. Fprintf is required for both of these assignments

Solution

Code:

y = input(\'How many years ago the experiment has started?: \');
m = input(\'How many months ago the experiment has started?: \');
d = input(\'How many days ago the experiment has started?: \');
h = input(\'How many hours ago the experiment has started?: \');
m = input(\'How many minutes ago the experiment has started?: \');
s = input(\'How many seconds ago the experiment has started?: \');

totalSeconds = s+60*m+3600*h+86400*d+2592000*m+31104000*y;
totalHours = totalSeconds/3600;

fprintf(\'%d years, %d months, %d days, %d hours, %d minutes, %d seconds ago the experiment was startd.\ \',y,m,d,h,m,s);

fprintf(\'%d seconds ago the experiment was started.\ \',totalSeconds);
fprintf(\'%d hours ago the experiment was started.\ \',totalHours);

Output:

How many years ago the experiment has started?: 3
How many months ago the experiment has started?: 6
How many days ago the experiment has started?: 24
How many hours ago the experiment has started?: 16
How many minutes ago the experiment has started?: 34
How many seconds ago the experiment has started?: 54
3 years, 34 months, 24 days, 16 hours, 34 minutes, 54 seconds ago the experiment was startd.
183573294 seconds ago the experiment was started.
5.099258e+04 hours ago the experiment was started.

 2. You are an electrical engineer performing tests on electric car batteries. You need to know how long the experiment has been running in seconds. For the pur

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site