Question

In: Computer Science

write a Program in C++ Using a structure (struct) for a timeType, create a program to...

write a Program in C++

Using a structure (struct) for a timeType, create a program to read in 2 times into structures, and call the method addTime, in the format:

t3 = addTime(t1, t2);

Make sure to use add the code to reset and carry, when adding 2 times. Also, display the resultant time using a function:

display(t3);

Solutions

Expert Solution

code in c++

(code to copy)

#include <bits/stdc++.h>
using namespace std;

//declare struct
struct timeType{
        int hour;
        int min;
};
void display(struct timeType t){
        cout<<t.hour<<":"<<t.min<<endl;
}
struct timeType addTime(struct timeType t1, struct timeType t2){
        struct timeType x;
        //add minutes
        x.min = t1.min+t2.min;
        //add hours
        x.hour = t1.hour+t2.hour+x.min/60; //add carry from minutes
        x.min=x.min%60; //reset minutes
        x.hour=x.hour%24; //reset hours
        return x;
}       

int main()
{
        struct timeType t1,t2;
        t1.hour=19;
        t1.min=40;
        t2.hour=10;
        t2.min=55;
        //display t1
        cout<<"t1: ";
        display(t1);
        
        //display t2
        cout<<"t2: ";
        display(t2);
        
        //display t1+t2
        cout<<"t1+t2: ";
        display(addTime(t1, t2));
}

code screenshot

sample code output screenshot

..


Related Solutions

Using C++ language, create a program that uses a struct with array variables that will loop...
Using C++ language, create a program that uses a struct with array variables that will loop at least 3 times and get the below information: First Name Last Name Job Title Employee Number Hours Worked Hourly Wage Number of Deductions Claimed Then, determine if the person is entitled to overtime and gross pay. Afterwards, determine the tax and net pay. Output everything to the screen. Use functions wherever possible. Bonus Points: Use an input file to read in an unknown...
Create a C++ program that follows the specifications below: *Define a struct with 4 or more...
Create a C++ program that follows the specifications below: *Define a struct with 4 or more members. *Application must have at least one user-defined function *Declare an array of your struct using a size of 10 or more *Load the date for each element in your array from a text file *Display the data in your array in the terminal *provide brief comments for each line of code
Write a C program that contains a structure that uses predefined types and union. • Create...
Write a C program that contains a structure that uses predefined types and union. • Create a struct with name, age, kind (Either child, college student, or adult), and kindOfPerson (Either kid, student, or adult) • kids have a school field. Students have college and gpa. Adults have company and salary. • Create one non-dynamic struct with the content for a college student: "Bob", 20, K-State, 3.5 • Create one struct dynamically for a kid with: "Alison", 10, "Amanda Arnold...
Create a schematic of a circuit using and write C program to run on a PIC...
Create a schematic of a circuit using and write C program to run on a PIC 16F88 that will flash between a red and green LED at 5Hz with the green on 75% of the time and the red on 25% of the time.
Write in C++: create a Doubly Linked List class that holds a struct with an integer...
Write in C++: create a Doubly Linked List class that holds a struct with an integer and a string. It must have append, insert, remove, find, and clear.
HW_6d - Write a struct object to a binary file. Create a new C++ project and...
HW_6d - Write a struct object to a binary file. Create a new C++ project and name it as:   Cats Create a Source.cpp file. Declare a struct named Cat. (in the Source.cpp file, or in a separate header file) Each Cat object has a name and age. The name data member is a c_string. The age data member is an integer. Ask the user to enter 3 cats. Use a while loop to read the information about one cat entered...
Write a program in C language 1- Define a struct for students with the aforementioned attributes,...
Write a program in C language 1- Define a struct for students with the aforementioned attributes, test it by populating one initialized struct variable with arbitrary input and take screenshots of the output. 2- For each student, struct add an array of number grades for a class the students are enrolled in such as S E 185. Then write functions which find the max, average, and minimum score for a specified assignment identified by a number, for example, Assignment 0...
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);
In c++, using stack structure, write a program that will take a sequence of characters (string)...
In c++, using stack structure, write a program that will take a sequence of characters (string) and determine whether it is a palindrome. Use the linked version of the stack.
Write a  program in c++ using a map to create the following output. Here is the list...
Write a  program in c++ using a map to create the following output. Here is the list of students: 100: Tom Lee 101: Joe Jones 102: Kim Adams 103: Bob Thomas 104: Linda Lee Enter a student an ID to get a student's name: ID:  103 students[103] - Bob Thomas # of students: 5 Delete a student (Y or N)?  Y Enter ID of student to be deleted:  103 Here is the list of students after the delete: 100: Tom Lee 101: Joe Jones...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT