Question

In: Computer Science

USE C++ and please keep program as simple as possible and also comment so it is...

USE C++ and please keep program as simple as possible and also comment so it is easy to understad

Create a structure called time. Its three members, all type int, should be called hours,
minutes, and seconds. Write a program that prompts the user to enter a time value in hours,
minutes, and seconds. This should be in 12:59:59 format. This entire input should be assigned
first to a string variable. Then the string should be tokenized thereby assigning the 1st token
to hours, 2nd token to minutes, and 3rd token to seconds member variables of the structure
called time. Finally inside a void Print_in_Seconds(void) member function of time structure,
it should print out the total number of seconds represented by this time value:
long totalsecs = t1.hours*3600 + t1.minutes*60 + t1.seconds

Solutions

Expert Solution

#include<iostream>
 
struct time   //specify the structure
    { 
    int seconds;   //three types are declared in int
    int minutes;
    int hours; 
     };

    void total_secs(struct time t1,struct time*totalsecs ); 

using namespace std;
 
int main()
{     
    struct time t1;    //total_secs and others probably aren't of type TIME, are they
    cout<<" Your Entered Time is: \n";
    cout<<"Enter the  Hours, Minutes and Seconds : "; 
    cin>>t1.hours>>t1.minutes>>t1.seconds;
    cout<<t1.hours<<":"<<t1.minutes<<":"<<t1.seconds<<endl;

    long total_secs = t1.hours*3600 + t1.minutes*60 + t1.seconds;  //Time value

    cout<<"Total number of seconds is :"<<total_secs<<endl;  //Printing Total number of seconds
 
    return 0;
}

OUTPUT:-


Related Solutions

C++ program, I'm a beginner so please make sure keep it simple Write a program to...
C++ program, I'm a beginner so please make sure keep it simple Write a program to read the input file, shown below and write out the output file shown below. Use only string objects and string functions to process the data. Do not use c-string functions or stringstream (or istringstream or ostringstream) class objects for your solution. Input File.txt: Cincinnati 27, Buffalo 24 Detroit 31, Cleveland 17 Kansas City 24, Oakland 7 Carolina 35, Minnesota 10 Pittsburgh 19, NY Jets...
PROGRAM LANGUAGE IN C, PLEASE KEEP IT SIMPLE EVEN IF IT IS REDUNDANT In this problem...
PROGRAM LANGUAGE IN C, PLEASE KEEP IT SIMPLE EVEN IF IT IS REDUNDANT In this problem you will take a list of names from the user and sort them alphabetically using selection sort. The code for selection sort for integer is available in the "Lab and Weekly Coding Solution module" in webcourses. Ask the user how many names the user wants to input. Let's say the number be N. Then take N number of names and put them in an...
PROGRAM LANGUAGE IN C NOT C# or C++ KEEP IT SIMPLE EVEN IF IT IS REDUNDANT...
PROGRAM LANGUAGE IN C NOT C# or C++ KEEP IT SIMPLE EVEN IF IT IS REDUNDANT PLEASE. Problem: Driving Function driving(): Write a function driving(), that updates the odometer and fuel gauge of a car. The function will take in a reference to the variables storing the odometer and fuel gauge readings, along with a double representing the miles per gallon (mpg) the car gets and the number of miles the driver intends to go. The function should update the...
(C++) keep things as simple as possible. I would love a good starting point with hints...
(C++) keep things as simple as possible. I would love a good starting point with hints to be able to finish it! Write a function called is valid phone number that takes a phone number as an array of characters and its size, and returns true if the input array is a valid phone number, false otherwise. A phone number is valid only if it is of the following format: (uuu) uuu-uuuu where u is from ‘0’, ‘1’, ‘2’, etc....
Week 10 - Please write in C++ as simple as possible RRCC has a schedule of...
Week 10 - Please write in C++ as simple as possible RRCC has a schedule of courses that includes: Subject (like: CSC) Course Number (like: 119) Section (like: 802) Credits (like: 3) Title Days (like: MW) Time (like 8:00am-9:15am) Instructor From this schedule information above create a class called RRCC_schedule (with a .cpp file and a .h file). Look at each item above and determine the type of data that will go into the variable. Then create a UML with...
As simple as possible. Please In C++ Computers are playing an increasing role in education. Write...
As simple as possible. Please In C++ Computers are playing an increasing role in education. Write a program that will help an elementary school student learn multiplication. Use rand() to produce two positive single digit integers. It should then display a question in the following format (assume 6 and 7 are randomly generated): How much is 6 * 7? The student then types the answer. Your program checks the student’s answer. If it is correct, print “Very good!” If the...
Code in C# please. Write a program that will use the greedy algorithm. This program will...
Code in C# please. Write a program that will use the greedy algorithm. This program will ask a user to enter the cost of an item. This program will ask the user to enter the amount the user is paying. This program will return the change after subtracting the item cost by the amount paid. Using the greedy algorithm, the code should check for the type of bill. Example: Cost of item is $15.50 User pays a $20 bill $20...
Please write in C++ as simple as possible I want you to create a Book Class...
Please write in C++ as simple as possible I want you to create a Book Class for a bookstore. I am not going to tell you what variables should go into it, that is for you to figure out (but you should have at least 5+). And then you must create a UML with all the variables and methods (like: the getters and setters, a default constructor, and a constructor that takes all the variables and finally the printValues() )....
Please code in C#-Visual Studio Tasks The program needs to contain the following A comment header...
Please code in C#-Visual Studio Tasks The program needs to contain the following A comment header containing your name and a brief description of the program Output prompting the user for the following inputs: Name as a string Length of a rectangle as a double Width of a rectangle as a double Length of a square as an int After accepting user input, the program outputs the following: User name Area of a rectangle with dimensions matching the inputs Area...
Please use C language and use link list to do this program. This program should ask...
Please use C language and use link list to do this program. This program should ask user to enter two fraction polynomials. Then user chocie if he want add it or multiple it. I need you please to test it to see if it work with these two fraction polynomials 1-  Left Poly Pointer: 1/1x2 + 3/4x + 5/12 2-Right Poly Pointer: 1/1x4 – 3/7x2 + 4/9x + 2/11 AND AFTER ADDING 3- Resulting Poly Pointer: 1/1x4 + 4/7x2 + 43/36x...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT