Please write a c++ code for my pseudo code. I am take a class that is teaching m
ID: 3881233 • Letter: P
Question
Please write a c++ code for my pseudo code. I am take a class that is teaching me flow charts and pseudocode and I would like to see the actual code so that I can start preparing myself for next semester’s classes.
Here is the pseudo code:
// main module
Module main()
// Local variables
Declare Integer Seconds, Days, Hours, Minutes
// Get the inputSeconds
Call getSeconds(Seconds)
// Calculate the days
If Seconds >= 86400 Then
Set Days = Seconds / 86400
Set Seconds = Seconds – (Days * 86400)
End If
// Calculate the hours
If Seconds >= 3600
Set Hours = Seconds / 3600
Set Seconds = Seconds – (Hours * 3600)
End If
// Calculate the minutes
If Seconds >= 60
Set Minutes = Seconds / 60
Set Seconds = Seconds – (Minutes * 60)
End If
// Display days, hours, minutes, seconds
Call showTime(Seconds, Days, Hours, Minutes)
End Module
// The getSeconds module gets seconds and stores it
// in the inputSeconds reference variable.
Module getSeconds(Integer Ref inputSeconds)
Display “Enter the seconds.”
Input inputSeconds
End Module
// The showTime module accepts Seconds, Days, Hours, Minutes
// as arguments and displays the number of each
Module showTime (Integer Seconds, Days, Hours, Minutes)
Display "Days: ", Days
Display "Hours: ", Hours
Display "Minutes: ", Minutes
Display "Seconds: ", Seconds
End Module
Explanation / Answer
#include <iostream>
using namespace std;
//Global variables declaration
int Seconds=0, Days=0,Hours=0, Minutes=0;
//method to display time - declaration and definition
void showTime(int Seconds,int Days,int Minutes,int Hours)
{
//display Days, Hours,Minutes and Seconds
cout<< "Days: " << Days <<endl;
cout<< "Hours: " << Hours <<endl;
cout<< "Minutes: " << Minutes <<endl;
cout<< "Seconds: " << Seconds <<endl;
}
/* Method to calculate Days, Hours,Minutes and Seconds accepting the input as seconds.*/
void getSeconds(int inputSeconds)
{
// calculating Days, Hours,Minutes and Seconds
if(inputSeconds>=86400)
{
Days=inputSeconds/86400;
inputSeconds=inputSeconds-(Days*86400);
}
if(inputSeconds>=3600)
{
Hours=inputSeconds/3600;
inputSeconds=inputSeconds-(Hours*3600);
}
if(inputSeconds>=60)
{
Minutes=inputSeconds/60;
Seconds=inputSeconds-(Minutes*60);
}
}
//Main Module
int main()
{
int inputSeconds;
//input the seconds
cout << "Enter the Seconds :" << endl;
cin >> inputSeconds;
cout<<"You have entered :" << inputSeconds <<endl;
//call getSeconds Method
getSeconds(inputSeconds);
//call showTime Method to display the output
showTime(Seconds,Days,Minutes,Hours);
}