Problem Solving with C++, Student Value Edition
10th Edition
ISBN: 9780134543680
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 10.1, Problem 2STE
Consider the following type definition:
struct ShoeType { char style; double price; }; |
Given this structure type definition, what will be the output produced by the following code?
ShoeType shoe1, shoe2; shoe1.style ='A'; shoe1.price = 9.99; cout << shoe1.style << " $" << shoe1.price << endl; shoe2 = shoe1; shoe2.price = shoe2.price/9; cout << shoe2.style << " $" << shoe2.price << endl; |
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
IN C++, create a class called Employee that includes three pieces of information as data members—a first name (type string), a last name (type string) and a monthly salary (type int). Your class should have a constructor that initializes the three data members. Provide a set and a get function for each data member. If the monthly salary is not positive, set it to 0. Write a test program that demonstrates class Employee’s capabilities. Create two Employee objects and display each object’s yearly salary. Then give each Employee a 10 percent raise and display each Employee’s yearly salary again.
Programming 2 - C++ Assignment:
Consider a class named Cars that have the following class members:• Public member: CarModel as string.• Public member: CarPrice as double.• Private member: CarColor as String.• Void function named PrintCarInfo().
(a) Write the complete class definition?(b) Create a class object named Mercedes-Benz of the class Cars in your main program?(c) Write the body of the member function PrintCarInfo(), that print the Cars information back to the user?
In C++, Create a class called Date that includes three data members: amonth(type int), a day(type int), and a year(type int). The Date class willhave a constructor with three parameters to initialize the three data members.You may assume the values provided for the year and day are correct, but makesure that the month value is in the range 1-12; if it isn't, set the month to1. Provide set and get functions for each data member. Provide a memberfunction displayDate that displays the date in format MM/DD/YYYY.Write a test program that prompts the user to input the month, the day,and the year and uses your Date class to output the formatted date.
Chapter 10 Solutions
Problem Solving with C++, Student Value Edition
Ch. 10.1 - Given the following structure and structure...Ch. 10.1 - Consider the following type definition: struct...Ch. 10.1 - What is the error in the following structure...Ch. 10.1 - Given the following struct definition: struct A {...Ch. 10.1 - Here is an initialization of a structure type....Ch. 10.1 - Write a definition for a structure type for...Ch. 10.1 - Prob. 7STECh. 10.1 - Prob. 8STECh. 10.1 - Give the structure definition for a type named...Ch. 10.1 - Declare a variable of type StockRecord (given in...
Ch. 10.2 - Below we have redefined the class DayOfYear from...Ch. 10.2 - Given the following class definition, write an...Ch. 10.2 - Prob. 13STECh. 10.2 - The private member function DayOfYear::checkDate...Ch. 10.2 - Suppose your program contains the following class...Ch. 10.2 - Suppose you change Self-Test Exercise 15 so that...Ch. 10.2 - Explain what public: and private: do in a class...Ch. 10.2 - a. How many public: sections are required in a...Ch. 10.2 - Give a definition for the function with the...Ch. 10.2 - Give a definition for the function with the...Ch. 10.2 - Give a definition for the function with the...Ch. 10.2 - Suppose your program contains the following class...Ch. 10.2 - How would you change the definition of the class...Ch. 10.2 - Prob. 24STECh. 10.3 - When you define an ADT as a C++ class, should you...Ch. 10.3 - When you define an ADT as a C++ class, what items...Ch. 10.3 - Suppose your friend defines an ADT as a C++ class...Ch. 10.3 - Redo the three- and two-parameter constructors in...Ch. 10.4 - How does inheritance support code reuse and make...Ch. 10.4 - Can a derived class directly access by name a...Ch. 10.4 - Suppose the class SportsCar is a derived class of...Ch. 10 - Solution to Practice Program 10.1 Redefine...Ch. 10 - Redo your definition of the class CDAccount from...Ch. 10 - Define a class for a type called CounterType. An...Ch. 10 - Write a grading program for a class with the...Ch. 10 - Redo Programming Project 1 (or do it for the first...Ch. 10 - Define a class called Month that is an abstract...Ch. 10 - Redefine the implementation of the class Month...Ch. 10 - My mother always took a little red counter to the...Ch. 10 - Write a rational number class. This problem will...Ch. 10 - Define a class called Odometer that will be used...Ch. 10 - Redo Programming Project 7 from Chapter 5 (or do...Ch. 10 - The U.S. Postal Service printed a bar code on...Ch. 10 - Consider a class Movie that contains information...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
The variable a starts with the value 10. The variable b starts with the value 2. The variable c starts with the...
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Code an SQL statement that creates a table with all columns from the parent and child tables in your answer to ...
Database Concepts (8th Edition)
T F All type parameters defined in a function template must appear at least once in the function parameter list...
Starting Out with C++ from Control Structures to Objects (9th Edition)
Suppose savings and expenses are variables of type double that have been given values. Write an if-else stateme...
Absolute Java (6th Edition)
What are the four basic arithmetic operations?
Digital Fundamentals (11th Edition)
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
- c++ program. Construct a class named Student consisting of an integer student ID number and a double-precision grade point average. The constructor for this class should initialize the ID number to 111111 and the grade point average to 0.0. Include an accessor function to display all data values. Note: Include the class constructed in the context of a complete program. Your program should declare two objects of type Student and display data for the two objects to verify operation of the class function.arrow_forwardProgram SpecificationUsing python, design a class named PersonData with the following member variables: lastName firstName address city state zip phone Write the appropriate accessor and mutator functions for these member variables. Next, design a class named CustomerData , which is derived from the PersonData class. The CustomerData class should have the following member variables: customerNumber mailingList The customerNumber variable will be used to hold a unique integer for each customer. The mailingList variable should be a bool . It will be set to true if the customer wishes to be on a mailing list, or false if the customer does not wish to be on a mail-ing list. Write appropriate accessor and mutator functions for these member variables. Next write a program which demonstrates an object of the CustomerData class in a program. Your program MUST use exception handling. You can choose how to implement the exception handling. Start your program with a welcome message Make sure…arrow_forwardC++ Program Complete the given Car class with set, get,and display functions as well as a constructor that accepts all the attributes for all five data members and demonstrate that you can create a second object of the class Car. Attributes: Object: Member Functions: string make VW Turn on, accelerate, brake, turn off string model PASSAT string color Red integer year 2020 integer mileage 0 Miles Here is the code that is given #include <iostream>#include<string>using namespace std; class Car{public:Car(string carMake, string carModel){make = carMake;model = carModel; } void setMake(string carMake){make = carMake;} string getMake(){return make;}void setModel(string carModel){model = carModel;} string getModel(){return model;} void displayCar(){cout << "Make: " << make << endl;cout << "Model:" << model << endl;}private:string make;string model;string color;int year;int mileage;}; int…arrow_forward
- In C++ Design a class named QuadraticEquation for a quadratic equation . The class contains: Data fields: a, b, and c that represents three coefficients. A default constructor A constructor for the arguments for a, b, and c. Three get functions for a, b, and c. Three set function for a, b and c. A function named getDiscriminant() that returns the discriminant, which is . Two member functions named getRoot1() and getRoot2() for returning two roots of the equation and These functions are useful only if the discriminant is non-negative. Let these functions return 0 if the discriminant is negative. Implement the class. Write a test program that prompts the user to enter values for , , and , and displays the result based on the discriminant. If the discriminant is positive, display the two roots. If the discriminant is 0, display the one root. Otherwise, display “The equation has no roots”.arrow_forwardQ#01: In this c++ program, you will be creating a class named Employee. Employee class has the following data members: Employee ID. Employee Name Department Employee Salary Static data member which will hold the value of total no. of employees Employee class must have the following member functions: Function Description Employee() Default constructor for Employee class, which will set employee id to 0, employee name to NULL, employee department to NULL and salary to 0.0 Employee(int, char *, char *, float); It will take employee id, employee name, department and salary as arguments and initialize their values using member initializer list Employee(Employee &); Copy constructor which will initialize one object with another object using deep copy Setter functions You have to define setter function for each data member which will take a value as an argument and set their values Getter functions You have to define getter function for each…arrow_forwardTHIS QUESTION IS RELATED TO SUBJECT OBJECT ORIENTED PROGRAMMING IN C++ . SOLVE this question in dev c++ . Do not change the names of functions and variables.Do not define extra functions except for required constructors. please send it in 30 minutes. THANKS Q#2 Write a class named Grade that has the following member variables and functions. Variables : protected: double score, char letter Functions: Required Constructors Getscore() // it will return score Getgrade() // it will assign the grades to letter variable and returns it. If score> 89 then A, > 79 then B, ..>69 then C, > 59 then D, else F. Derive a class named PassFail publically from class Grade that has the following member variables and functions. Variables: private: MinPassing Functions: Required constructors Getgrade() // it will return “P” if score >=MinPassing else return “F” Derive a class named FinalExam publically from class PassFail that has the…arrow_forward
- In C++ design a class named Triangle that extends GeometricObject. The class contains the following: Three double data fields named side1, side2, and side3 to denote three sides of the triangle. A no-arg constructor that creates a default triangle with each side 1.0. A constructor that creates a rectangle with the specified side1, side2, and side3. The constant accessor functions for all three data fields. A constant function named getArea() that returns the area of this triangle. A constant function named getPerimeter() that returns the perimeter of this triangle. Submit the following: Draw the UML diagram that involves the classes Triangle and GeometricObject. Implement the class. Write a test program that prompts the user to enter three sides of the triangle, enter a color, and enter 1 or 0 to indicate whether the triangle is filled. The program should create a Triangle object with these sides and set the color and filled properties using the input. The program should display the…arrow_forwardProblem: Create a Fraction class with two private positive integer member variables numerator and denominator, one constructor with two integer parameters num and den with default values 0 and 1, one display function that print out a fraction in the format numerator/denominator in the proper form such as 2/3 or ½ . Note: 2/4 should be displayed as ½.arrow_forwardPLease! IN C++ Write A Class Declare a class/struct named NutritionData that contains these private fields foodName (string) servingSize (int) calFromCarb (double) calFromFat (double) calFromProtein (double) Use the data types in parentheses for the fields. Note that you need to use the proper C++ syntax for the fields. Each field should have a comment documenting what it is for. Place one comment above each field. Add the public default constructor. Read the textbook for the syntax of the default constructor. Write the body of the default constructor inline. The default constructor initializes the fields so that the food name is an empty string and all other fields are 0 for int and 0.0 for double. Add public mutator member functions to set the fields. One mutator member function for each field. Each mutator member function's name should begin with the word 'set' followed by the field name with the first letter changed to uppercase. Each member function should have a comment above…arrow_forward
- For C++ Programming II D.S. Malik Programming Exercise 10-16: Write the definition of a class swimmingPool, to implement the properties of a swimming pool. Your class should have the instance variables to store the length (in feet), width (in feet), depth (in feet), the rate (in gallons per minute) at which the water is filling the pool, and the rate (in gallons per minute) at which the water is draining from the pool. Add appropriate constructors to initialize the instance variables. Also, add member functions to do the following: determine the amount of water needed to fill an empty or partially filled pool, determine the time needed to completely or partially fill or empty the pool, and add or drain water for a specific amount of time, if the water in the pool exceeds the total capacity of the pool, output "Pool overflow" to indicate that the water has breached capacity. The header file for the swimmingPool class has been provided for reference. Write a program to test your…arrow_forwardCreate a class called Employee that includes four pieces of information as data members — a first name (type string), a middle name (type string) , a last name (type string)and a monthly salary (type int). Your class should have a constructor that initializes the four data members. Provide a set and a get function for each data member. If the monthly salary is not positive, set it to 0. Write a c++ test program that demonstrates class Employee’s capabilities. Create two Employee objects and display each object’s yearly salary.arrow_forwardWrite a program in c++ that has a class containing constructors and in the class create 5 functions two functions should be get data and print data functions while rest of the 3 could be of programmers choice depending on the type of class is being created *c++ coding *create a class(any class of choice such as book car animal etc) *the class should contain constructors *In class create get data and print data functions for storing and printing data *Then create / include three (3) more functions of any type (other than get data and print data) *In total there will be 5 functions in class . get data . Print data . And three 3 more of programmers choice depending on whatever the class requires * keep the program simple and basic as possible for a beginner level student in c ++arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
C++ Data Members; Author: CppNuts;https://www.youtube.com/watch?v=StlsYRNnWaE;License: Standard YouTube License, CC-BY