Question

In: Computer Science

use c++ language. Create a structure called time. Its three members, all type int, should be...

use c++ language. 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

comment your code properly. do not use vectors

before coding explain it in simple words and use your own logic

Solutions

Expert Solution

Code:

// C++ program to convert 12 hour to 24 hour
// format
#include<iostream>
#include<string>
using namespace std;
struct time{
   int hours;
   int minutes;
   int seconds;
  
   void print(){
       cout<<"Total Second: "<<hours*3600+minutes*60+seconds;
   }
};
time Tokenize(string str)
{
   time t;
   // Get hours
   int h1 = (int)str[1] - '0';
   int h2 = (int)str[0] - '0';
   int hh = (h2 * 10 + h1 % 10);
   int count=0;
   int min=0,sec=0;
   for (int i=3; i <= 7; i++){
       if(i==3 || i==4){
       min=min*10+((int)(str[i]-'0'));  
       }
       else if(i==6 || i==7){
       sec=sec*10+((int)(str[i]-'0'));  
       }
   }
   t.hours=hh;
   t.minutes=min;
   t.seconds=sec;
   return t;

}

// Driver code
int main()
{
   cout<<"Enter Time- 00:00:00 Formate: ";
string str;
cin>>str;
time t=Tokenize(str);
t.print();
return 0;
}

Output:


Related Solutions

c++ language Create a file program that reads an int type Array size 10; the array...
c++ language Create a file program that reads an int type Array size 10; the array has already 10 numbers, but your job is to resize the array, copy old elements of array to the new one and make it user input and add an additional 5 slots in the array, and lastly do binary search based on user input. close the file.
Create a structure in C called BarcelonaPlayer with the following members. struct BarcelonaPlayer { char name[20];...
Create a structure in C called BarcelonaPlayer with the following members. struct BarcelonaPlayer { char name[20]; int age; char country[20]; char Position[20]; double Salary; double Rating; }; First, create an array of BarcelonaPlayer structures. Now, write a function that takes an array of BarcelonaPlayer structures as input and find out the highest paid player among all the players. void highestPaidPlayer(struct BarcelonaPlayer *pl, int size); Create another function that finds all the players from Argentina. void findPlayers(struct BarcelonaPlayer *pl, int size);
(Use C++ language) CREATE A PROGRAM CALLED and or not.cpp THAT: ASKS USER FOR AGE Note:...
(Use C++ language) CREATE A PROGRAM CALLED and or not.cpp THAT: ASKS USER FOR AGE Note: you must be 18 or older to vote && is the symbol for And | | is the symbol for Or ! is the symbol for Not USE AND, OR, OR NOT TO SEE IF THEY'RE OLD ENOUGH TO VOTE and display appropriate message USE AND, OR, OR NOT TO SEE IF THEY ENTERED A NUMBER LESS THAN 0 and display appropriate message USE...
Have to use C language Pseudocode A #define called BITS should be set at the top...
Have to use C language Pseudocode A #define called BITS should be set at the top of the program. It should be set to 8 when the program is submitted. This define should be used throughout the entire program when setting/using array sizes/max element. This define will also be used in the output to print 8-bit vs 16 bit. Your program should function whether the define is set to 8 or to 16. Part of the grading process will be...
Create separate class with these members a, b, c, x, y, z int a b c...
Create separate class with these members a, b, c, x, y, z int a b c float x y z Demonstrate 3) A two arg float, int constructor, and a three arg int, float, float constructor to instantiate objects, initialize variables read from the keyboard, display the sum Note:- Please type and execute this above java program and also give the output for both problems. (Type a java program)
Create separate class with these members a, b, c, x, y, z int a b c...
Create separate class with these members a, b, c, x, y, z int a b c float x y z Demonstrate 1) A two arg float constructor, and a two arg int constructor to instantiate objects, initialize variables read from the keyboard, display the sum. Note:- Please type and execute this above java program and also give the output for both problems. (Type a java program)
Write C code to create a structure called time_of_day, which stores the current time in hours,...
Write C code to create a structure called time_of_day, which stores the current time in hours, minutes, and seconds. All the fields should be integers except for seconds, which should be a floating point value. Write a C function called check_time, which takes a pointer to a time_of_day structure as input, and return 1 if the time is valid (0 to 23 hours, 0 to 59 minutes, 0 to 59.999999 seconds) and 0 otherwise. Assume that times are stored in...
Use C++ language Create a program which will ask the user to input three songs for...
Use C++ language Create a program which will ask the user to input three songs for a playlist (you may use TV shows or movies, if you prefer). Declare three strings to store each of the songs. Use getline to receive the input. Display output which lists each of the songs (or movies or tv shows), on separate lines, with a title on the first line: My Playlist. Insert three lines of comments at the beginning of the program for...
Create a class called FibGenerator with 3 methods: public int nthFib(int n). This method should call...
Create a class called FibGenerator with 3 methods: public int nthFib(int n). This method should call computeFibRecurse(n). private int computeFibRecurse(int n), which should recurse (that is, call itself) unless n is 1 or 2. If n is 1 or 2, the method should return 1. A main method that prints “STARTING”, then constructs a FibGenerator generator and then calls nthFib(), passing in interesting values. To look into this problem, you’re going to use software to analyze software. Add an instance...
C++ language You will create a Hangman class. Possible private member variables: int numOfCharacters; //for the...
C++ language You will create a Hangman class. Possible private member variables: int numOfCharacters; //for the secret word char * secretWord; char *guessedWord; public: //please create related constructors, getters, setters,constructor() constructor() You will need to initialize all member variables including the two dynamic variables. destructor() Please deallocate/freeup(delete) the two dynamic arrays memories. guessALetter(char letter) 1.the function will check if the letter guessed is included in the word. 2. display the guessed word with related field(s) filled if the letter guessed...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT