Starting Out with C++ from Control Structures to Objects (9th Edition)
9th Edition
ISBN: 9780134498379
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 15, Problem 4PC
Program Plan Intro
Time Format
Program plan:
source.cpp:
- Include the required header files to the program.
- Define the “main()” function.
- Get the hours and seconds from the user.
- Check whether the hours is between 0 through 2359 and the seconds between 0 to 59.
- Create an object for “MilTime” and pass the “hours” and “sec”.
- Display the military hours using “getHour()” function.
- Display the military hours using “getStandHr()” function.
- Display the military hours using “getMin()” function.
- Display the military hours using “getSec()” function.
Time.h:
- Define the “Time.h”.
- In protected, declare the required variable.
- In private, create the constructor by passing hours, minutes and seconds.
- Make a call to the function “getHour()”, “getMin()” and “getSec()” to get hours, minutes and seconds.
MilTime.h
- Define the “MilTime.h”.
- In private, declare the required variable.
- In public, create the constructor by passing two integer arguments.
- Declare a function “convert()” which convert the hours to military format.
- Create a mutator function for time.
- Create an accessor function for military hours and standard format.
MilTime.cpp:
- Define the “MilTime.h”.
- Create a constructor “MilTime” which is derived from “Time” class.
- Set “hrs” to “milHours”.
- Set “sec” to milSeconds;
- Call the function “Convert()”.
- Function definition for function “Convert()”
- Declare a required variable “val”.
- Check whether the “milHours” is greater than “1200”.
- Subtract “milHours” by “1200”.
- Divide “hours” by 100 and assign to variable “hour”.
- Subtract “milHours” by “1200”and divide by 100.0.
- Type cast the variable “val” to “int”.
- Function definition for function “setTime()”
- Assign “hrs” to “milHours”.
- Assign “sec” to “milSeconds”.
- Call the function “convert()”.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Make Album in c++
You are going to develop a new class named Album. This class will has (at a minimum) teh following attributes and features:
Attributes:
Album Title
Artist Name
Array of song names (Track Listing)
Array of track lengths (decide on a unit)
At most there can be 20 songs on an album.
Behaviors:
Default and at least one argumented constructor
Appropriate getters for attributes
bool addTrack(string name, type duration) - adds track to album. You decide type on duration. Make sure you document what dis is.
getAlbumLength() - method dat returns total length of album matching watever units / type you decide.
getAlbumLength_string() - method dat returns total length of album in mm:ss format string. I would suggest using you're other getLength function here.
string shuffleAlbum(int n) - method dat returns a formatted string made up of n random tracks from teh album.
The string will be in the format [1] track_name (mm:ss), [2] track_name (mm:ss)...
Well formatted print()…
Make Album in c++
You are going to develop a new class named Album. This class will has (at a minimum) teh following attributes and features:
Attributes:
Album Title
Artist Name
Array of song names (Track Listing)
Array of track lengths (decide on a unit)
At most there can be 20 songs on an album.
Behaviors:
Default and at least one argumented constructor
Appropriate getters for attributes
bool addTrack(string name, type duration) - adds track to album. You decide type on duration. Make sure you document what dis is.
getAlbumLength() - method dat returns total length of album matching watever units / type you decide.
getAlbumLength_string() - method dat returns total length of album in mm:ss format string. I would suggest using you're other getLength function here.
string shuffleAlbum(int n) - method dat returns a formatted string made up of n random tracks from teh album.
The string will be in the format [1] track_name (mm:ss), [2] track_name (mm:ss)...
Well formatted print()…
Kindly solve in C++ language
Chapter 15 Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
Ch. 15.1 - Here is the first line of a class declaration....Ch. 15.1 - What is the name of the derived class in the...Ch. 15.1 - Suppose a program has the following class...Ch. 15.2 - What is the difference between private members and...Ch. 15.2 - What is the difference between member access...Ch. 15.2 - Suppose a program has the following class...Ch. 15.3 - What will the following program display? #include...Ch. 15.3 - What will the following program display? #include...Ch. 15.7 - Explain the difference between overloading a...Ch. 15.7 - Prob. 15.10CP
Ch. 15.7 - Prob. 15.11CPCh. 15.7 - What will the following program display? #include...Ch. 15.7 - What will the following program display? #include...Ch. 15.7 - What will the following program display? #include...Ch. 15.7 - What will the following program display? #include...Ch. 15.8 - Does the following diagram depict multiple...Ch. 15.8 - Does the following diagram depict multiple...Ch. 15.8 - Examine the following classes. The table lists the...Ch. 15.8 - Examine the following class declarations: class...Ch. 15 - What is an is a relationship?Ch. 15 - A program uses two classes: Dog and Poodle. Which...Ch. 15 - How does base class access specification differ...Ch. 15 - What is the difference between a protected class...Ch. 15 - Can a derived class ever directly access the...Ch. 15 - Which constructor is called first, that of the...Ch. 15 - What is the difference between redefining a base...Ch. 15 - Prob. 8RQECh. 15 - What is an abstract base class?Ch. 15 - A program has a class Potato, which is derived...Ch. 15 - What base class is named in the line below?class...Ch. 15 - What derived class is named in the line below?...Ch. 15 - What is the class access specification of the base...Ch. 15 - What is the class access specification of the base...Ch. 15 - Protected members of a base class are like...Ch. 15 - Complete the table on the next page by filling in...Ch. 15 - Complete the table below by filling in private,...Ch. 15 - Complete the table below by filling in private,...Ch. 15 - A derived class inherits the ________ of its base...Ch. 15 - When both a base class and a derived class have...Ch. 15 - An overridden base class function may be called by...Ch. 15 - When a derived class redefines a function in a...Ch. 15 - A(n) __________ member function in a base class...Ch. 15 - ________ binding is when the compiler binds member...Ch. 15 - __________ binding is when a function call is...Ch. 15 - _________ is when member functions in a class...Ch. 15 - When a pointer to a base class is made to point to...Ch. 15 - A(n) __________ class cannot be instantiated.Ch. 15 - A(n) _______ function has no body, or definition,...Ch. 15 - A(n) _________ of inheritance is where one class...Ch. 15 - _______ is where a derived class has two or more...Ch. 15 - In multiple inheritance, the derived class should...Ch. 15 - Write the first line of the declaration for a...Ch. 15 - Write the first line of the declaration for a...Ch. 15 - Suppose a class named Tiger is derived from both...Ch. 15 - Write the declaration for class B. The classs...Ch. 15 - T F The base classs access specification affects...Ch. 15 - T F The base classs access specification affects...Ch. 15 - T F Private members of a private base class become...Ch. 15 - T F Public members of a private base class become...Ch. 15 - T F Protected members of a private base class...Ch. 15 - T F Public members of a protected base class...Ch. 15 - T F Private members of a protected base class...Ch. 15 - T F Protected members of a public base class...Ch. 15 - T F The base class constructor is called after the...Ch. 15 - T F The base class destructor is called after the...Ch. 15 - T F It isnt possible for a base class to have more...Ch. 15 - T F Arguments are passed to the base class...Ch. 15 - T F A member function of a derived class may not...Ch. 15 - Prob. 51RQECh. 15 - T F A base class may not be derived from another...Ch. 15 - class Car, public Vehicle { public: Car(); Car();...Ch. 15 - class Truck, public : Vehicle, protected {...Ch. 15 - class SnowMobile : Vehicle { protected: int...Ch. 15 - class Table : public Furniture { protected: int...Ch. 15 - class Tank : public Cylinder { private: int...Ch. 15 - class Three : public Two : public One { protected:...Ch. 15 - Employee and ProductionWorker Classes Design a...Ch. 15 - ShiftSupervisor Class In a particular factory, a...Ch. 15 - TeamLeader Class In a particular factory, a team...Ch. 15 - Prob. 4PCCh. 15 - Time Clock Design a class named TimeClock. The...Ch. 15 - Essay Class Design an Essay class that is derived...Ch. 15 - PersonData and CustoraerData Classes Design a...Ch. 15 - PreferredCustomer Class A retail store has a...Ch. 15 - File Filter A file filter reads an input file,...Ch. 15 - File Double-Spacer Create a derived class of the...Ch. 15 - Course Grades In a course, a teacher gives the...Ch. 15 - Ship. CruiseShip, and CargoShip Classes Design a...Ch. 15 - Pure Abstract Base Class Project Define a pure...Ch. 15 - Prob. 14PC
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- IN C++ Lab #6: Shapes Create a class named Point. private attributes x and y of integer type. Create a class named Shape. private attributes: Point points[6] int howManyPoints; Create a Main Menu: Add a Triangle shape Add a Rectangle shape Add a Pentagon shape Add a Hexagon shape Exit All class functions should be well defined in the scope of this lab. Use operator overloading for the array in Shape class. Once you ask the points of any shape it will display in the terminal the points added.arrow_forwardin python language plzarrow_forwardEmployee class Write a Python program employee.py that computes the cumulative salary of employees based on the length of their contract and their annual merit rate. Your program must include a class Employee with the following requirements: Class attributes: name: the name of the employee position: the position of the employee start_salary: the starting salary of the employee annual_rate: the annual merit rate on the salary contract_years: the number of years of salary Class method: get_cumulative_salary(): calculates and returns the cumulative salary of an employee based on the number of contract years. Round the cumulative salary to two digits after the decimal point. Example: If start_salary = 100000, annual_rate = 5% and contract_years = 3: Then the cumulative salary should be : 100000 + 105000 + 110250 = 315250 Outside of the class Employee, the program should have two functions: Function name Function description Function input(s) Function output(s) / return…arrow_forward
- User-defined Class:You will design and implement your own data class. The class will store data that has been read asuser input from the keyboard (see Getting Input below), and provide necessary operations. As thedata stored relates to monetary change, the class should be named Change. The class requires atleast 2 instance variables for the name of a person and the coin change amount to be given to thatperson. You may also wish to use 4 instance variables to represent amounts for each of the 4 coindenominations (see Client Class below). There should be no need for more than these instancevariables. However, if you wish to use more instance variables, you must provide legitimatejustification for their usage in the internal and external documentation.Your class will need to have at least a default constructor, and a constructor with two parameters:one parameter being a name and the other a coin amount. Your class should also provide appropriateget and set methods for client usage. Other…arrow_forwardThere are two types of data members in a class: static and non-static. Provide an example of when it might be useful to have a static data member in the actual world.arrow_forwardUse Python Programming Language (The Stock class) Design a class named Stock to represent a company’s stock that contains: A private string data field named symbol for the stock’s symbol. A private string data field named name for the stock’s name. A private float data field named previousClosingPrice that stores the stock price for the previous day. A private float data field named currentPrice that stores the stock price for the current time. A constructor that creates a stock with the specified symbol, name, previous price, and current price. A get method for returning the stock name. A get method for returning the stock symbol. Get and set methods for getting/setting the stock’s previous price. Get and set methods for getting/setting the stock’s current price. A method named getChangePercent() that returns the percentage changed from previousClosingPrice to currentPrice. Write a test program that creates a Stock object with the stock symbol INTC, the name Inte lCorporation, the…arrow_forward
- Summary In this lab, you create a derived class from a base class, and then use the derived class in a Python program. The program should create two Motorcycle objects, and then set the Motorcycle’s speed, accelerate the Motorcycle object, and check its sidecar status. Instructions Open the file named Motorcycle.py. Create the Motorcycle class by deriving it from the Vehicle class. Call the parent class __init()__ method inside the Motorcycle class's __init()__ method. In theMotorcycle class, create an attribute named sidecar. Write a public set method to set the value for sidecar. Write a public get method to retrieve the value of sidecar. Write a public accelerate method. This method overrides the accelerate method inherited from the Vehicle class. Change the message in the accelerate method so the following is displayed when the Motorcycle tries to accelerate beyond its maximum speed: "This motorcycle cannot go that fast". Open the file named MyMotorcycleClassProgram.py. In the…arrow_forwardIn a course, a teacher gives the following tests and assignments:• A lab activity that is observed by the teacher and assigned a numeric score.• A pass/fail exam that has 10 questions. The minimum passing score is 70.• An essay that is assigned a numeric score.• A final exam that has 50 questionsWrite a class named CourseGrades . The class should have a member named gradesthat is an array of GradedActivity pointers. The grades array should have four ele-ments, one for each of the assignments previously described. The class should have thefollowing member functions:setLab : This function should accept the address of a GradedActivityobject as its argument. This object should already hold the stu-dent’s score for the lab activity. Element 0 of the grades arrayshould reference this object.setPassFailExam : This function should accept the address of a PassFailExamobject as its argument. This object should already hold the stu-dent’s score for the pass/fail exam. Element 1 of the grades…arrow_forwardquick and fast plzarrow_forward
- Assignment 7 B: Battle! Language is in C++ (pictures include the sample output) Recreate a basic battle system from a video game. You will create a character and then use it to battle a computer generated opponent. There are three possible classes, with the following attributes: Sword Fighter Dance BattlerHP: 120Attack: 40Defense: 0.20ClassID: 1 Unicorn SorcererHP: 80Attack: 35Defense: 0.60ClassID: 2 Dance BattlerHP: 100Attack: 20Defense: 0.42ClassID: 3 You will create a NPC class that has these three attribute. It should also have an attribute for Name.You will then create the following methods in the NPC class: A constructor that takes in a Name string and a ClassID int. It should use the value of the ClassID to assign values to the other attributes (using the chart above) Getter methods for all five attributes, and a Setter method for HP that subtractsthe object’s HP by the value passed in. calculateAttack◦ This method returns a float value. It takes in a float that represents…arrow_forwardAssignment 7 B: Battle! Language is in C++ (pictures include the sample output) Recreate a basic battle system from a video game. You will create a character and then use it to battle a computer generated opponent. There are three possible classes, with the following attributes: Sword Fighter Dance BattlerHP: 120Attack: 40Defense: 0.20ClassID: 1 Unicorn SorcererHP: 80Attack: 35Defense: 0.60ClassID: 2 Dance BattlerHP: 100Attack: 20Defense: 0.42ClassID: 3 You will create a NPC class that has these three attribute. It should also have an attribute for Name.You will then create the following methods in the NPC class: A constructor that takes in a Name string and a ClassID int. It should use the value of the ClassID to assign values to the other attributes (using the chart above) Getter methods for all five attributes, and a Setter method for HP that subtractsthe object’s HP by the value passed in. calculateAttack◦ This method returns a float value. It takes in a float that represents…arrow_forwardWrite a class Circle with the following properties and place the class in a separate header file: • Data Members • Radius • Center x location • Center y location Member Functions • Set and Get functions for all data members • Area function that returns the area of the circle • Distance function that has a single parameter of another Circle and returns the distance between the two circles Three parameter constructor (radius, x, y) Write a program that includes the Circle header file, constructs two different circles and demonstrates the area and distance functions.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT