Starting Out With C++: Early Objects (10th Edition)
10th Edition
ISBN: 9780135235003
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 7, Problem 40RQE
Program Plan Intro
Structure:
- Structure is a “user-defined” data type.
- To use structure variables in the
programming language, it is important to declare the structure. - Member variables are declared inside the structure.
- Members can be accessed with the structure name or structure object.
- Name of the structure name is also called as “tag”. It is declared before variable declaration.
- Variables can be accessed with the help of a “tag”.
Syntax:
struct structure_Name
{
//variable declarations;
}structure_Object;
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
An Inventory structure is declared as follows:
struct Inventory{int itemCode; int qtyOnHand;};
Write a definition statement that creates an Inventory variable named trivet and initializes it with an initialization list so that its code is 555 and its quantity is110.
Define a struct type that represents an exercise plan. The struct should store the following data: plan name (a character array of size 50) and goal calories to burn (an integer). The type should be renamed from struct exercise_plan to Exercise_plan.
Declare three structs:
Struct TravelInfo{
String name;
Double weight;
Double newWeight;
Int planetChoice;
Int speed;
};
Struct TravelTimeCalc{
Int totalTravelTime;
Int years;
Int days;
Int hours;
};
Struct Planet{
String planetNames;
Double distanceFromSun;
Double gravity;
};
Planets, distance from sun(millions of miles), surface gravity as a percent of earth’s gravity:
Mercury 36 0.27
Venus 67 0.86
Earth 93 1.00
Mars 141 0.37
Jupiter 483 2.64
Saturn 886 1.17
Uranus 1782 0.92
Neptune 2793 1.44
Pass the arrays to the FillPlanetInfo function that will load the data into the three arrays.
Start a do while loop in main
Pass the function AskSpaceTravellerInfo a reference to the TravelerInfo struct variable and the array of planet names. Get the user’s name, Earth weight, the speed they want to travel and the planet they wish to visit. Provide a menu with the planet names and a way for the user to select the chosen destination.
Pass the data you obtained…
Chapter 7 Solutions
Starting Out With C++: Early Objects (10th Edition)
Ch. 7.5 - Which of the following shows the correct use of...Ch. 7.5 - An objects private member variables can be...Ch. 7.5 - Assuming that soap is an instance of the Inventory...Ch. 7.5 - Complete the following code skeleton to declare a...Ch. 7.7 - Briefly describe the purpose of a constructor.Ch. 7.7 - Constructor functions have the same name as the A)...Ch. 7.7 - A constructor that requires no arguments is called...Ch. 7.7 - Assume the following is a constructor: ClassAct: :...Ch. 7.7 - Prob. 7.9CPCh. 7.7 - True or false: A class may have a constructor with...
Ch. 7.7 - A destructor function name always starts with A) a...Ch. 7.7 - True or false: Just as a class can have multiple...Ch. 7.7 - What will the following program code display on...Ch. 7.7 - What will the following program code display on...Ch. 7.9 - 7.15 private class member function can be called...Ch. 7.9 - When an object is passed to a function, a copy of...Ch. 7.9 - If a function receives an object as an argument...Ch. 7.9 - Prob. 7.18CPCh. 7.9 - Prob. 7.19CPCh. 7.10 - Prob. 7.20CPCh. 7.10 - Write a class declaration for a class named...Ch. 7.10 - Write a class declaration for a class named Pizza...Ch. 7.10 - Write four lines of code that might appear in a...Ch. 7.11 - Assume the following class components exist in a...Ch. 7.11 - What header files should be included in the client...Ch. 7.12 - Write a structure declaration for a structure...Ch. 7.12 - Prob. 7.27CPCh. 7.12 - Prob. 7.28CPCh. 7.12 - Write a declaration for a structure named...Ch. 7.12 - Write a declaration for a structure named City,...Ch. 7.12 - Write assignment statements that store the...Ch. 7.12 - Prob. 7.32CPCh. 7.12 - Write a function that uses a Rectangle structure...Ch. 7.12 - Prob. 7.34CPCh. 7.15 - Prob. 7.35CPCh. 7.15 - When designing an object -oriented application,...Ch. 7.15 - How do you identify the potential classes in a...Ch. 7.15 - What two questions should you ask to determine a...Ch. 7.15 - Look at the following description of a problem...Ch. 7 - Prob. 1RQECh. 7 - Which of the following must a programmer know...Ch. 7 - Prob. 3RQECh. 7 - ______programming is centered around functions, or...Ch. 7 - An object is a software entity that combines both...Ch. 7 - An object is a(n) ______ of a class.Ch. 7 - Prob. 7RQECh. 7 - Once a class is declared, how many objects can be...Ch. 7 - An objects data items are stored in its...Ch. 7 - The procedures, or functions, an object performs...Ch. 7 - Bundling together an objects data and procedures...Ch. 7 - An objects members can be declared public or...Ch. 7 - Normally a classs _________ are declared to be...Ch. 7 - A class member function that uses, but does not...Ch. 7 - A class member function that changes the value of...Ch. 7 - When a member functions body is written inside a...Ch. 7 - A class constructor is a member function with the...Ch. 7 - A constructor is automatically called when an...Ch. 7 - Constructors cannot have a(n) ______ type.Ch. 7 - A(n) ______ constructor is one that requires no...Ch. 7 - A destructor is a member function that is...Ch. 7 - A destructor has the same name as the class but is...Ch. 7 - A constructor whose parameters all have default...Ch. 7 - A class may have more than one constructor, as...Ch. 7 - Prob. 25RQECh. 7 - In general, it is considered good practice to have...Ch. 7 - When a member (unction forms part of the interface...Ch. 7 - When a member function performs a task internal to...Ch. 7 - True or false: A class object can be passed to a...Ch. 7 - Prob. 30RQECh. 7 - It is considered good programming practice to...Ch. 7 - If you were writing a class declaration for a...Ch. 7 - If you were writing the definitions for the Canine...Ch. 7 - A structure is like a class but normally only...Ch. 7 - By default, are the members of a structure public...Ch. 7 - Prob. 36RQECh. 7 - When a structure variable is created its members...Ch. 7 - Prob. 38RQECh. 7 - Prob. 39RQECh. 7 - Prob. 40RQECh. 7 - Prob. 41RQECh. 7 - Write a function called showReading. It should...Ch. 7 - Write a function called input Reading that has a...Ch. 7 - Write a function called getReading, which returns...Ch. 7 - Indicate whether each of the following enumerated...Ch. 7 - Prob. 46RQECh. 7 - Assume a class named Inventory keeps track of...Ch. 7 - Write a remove member function that accepts an...Ch. 7 - Prob. 49RQECh. 7 - A) struct TwoVals { int a, b; } ; int main() { }...Ch. 7 - A) struct Names { string first; string last; } ;...Ch. 7 - A) class Circle: { private double centerX; double...Ch. 7 - A) class DumbBell; { int weight; public: void set...Ch. 7 - If the items on the following list appeared in a...Ch. 7 - Look at the following description of a problem...Ch. 7 - Soft Skills Working in a team can often help...Ch. 7 - Date Design a class called Date that has integer...Ch. 7 - Report Heading Design a class called Heading that...Ch. 7 - Widget Factory Design a class for a widget...Ch. 7 - Car Class Write a class named Car that has the...Ch. 7 - Population In a population, the birth rate and...Ch. 7 - Gratuity Calculator Design a Tips class that...Ch. 7 - Inventory Class Design an Inventory class that can...Ch. 7 - Movie Data Write a program that uses a structure...Ch. 7 - Movie Profit Modify the Movie Data program written...Ch. 7 - Prob. 10PCCh. 7 - Prob. 11PCCh. 7 - Ups and Downs Write a program that displays the...Ch. 7 - Wrapping Ups and Downs Modify the program you...Ch. 7 - Left and Right Modify the program you wrote for...Ch. 7 - Moving Inchworm Write a program that displays an...Ch. 7 - Coin Toss Simulator Write a class named Coin. The...Ch. 7 - Tossing Coins for a Dollar Create a game program...Ch. 7 - Fishing Came Simulation Write a program that...Ch. 7 - Group Project 19. Patient Fees This program should...
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
- explain answerarrow_forwardConsider the following structure and declarations: struct Player { string firstName; string lastName; int hits; int runs; }; int main() { Player p = { "Jackie", "Robinson", 1518, 947 }; Player team[24]; Player *tPtr = team; team[0] = p; // INSERT CODE HERE } The statement tPtr = *team; will assign the memory address of the first element of team array to tPtr **Notice the star in *team, that way its accurate*** A.) True B.) Falsearrow_forwardneed code in C++ answer all parts Assume the Product structure is declared as follows: struct Product{string description; // Product descriptionint partNum; // Part numberdouble cost; // Product cost};1. Add two constructors to the Product structure declaration. The firstshould be a default constructor that sets the description member to the null string and the partNum and cost members to zero. The second con-structor should have three parameters: a string, an int, and a double. It should copy the values of the arguments into the description, partNum,and cost members.2. Define a print function as member of the struct that prints an object ofthis struct in the following format.Description: Claw Hammer PartNumber: 547Part Cost: $8.293. Declare an array of size 5 with pointers and named it ”items”. Initilize itwith user input values.4. Write a print function (not as a member of the struct) and pass a pointerto the pointer that points to the array(double pointer) and print all theitems of…arrow_forward
- #include <iostream>#include <string>#include <iomanip>using namespace std;// structurestruct Hat{string brand;string color;float price;};// Customer structurestruct Customer{string fullName ;int age ;Hat hat; // Hat structure (nested in Customer)};int main(){// declare 5 variables of CustomerCustomer customer_1,customer_2,customer_3,customer_4,customer_5;cout<<"Welcome to Hats For U!\n";cout<<"Customer 1\n";cout<<"Enter customer's Full Name: ";getline(cin,customer_1.fullName);cout<<"Enter customer's age: ";cin>>customer_1.age;cout<<"Enter the brand of hat: ";cin>>customer_1.hat.brand;cout<<"Enter the hat color: ";cin>>customer_1.hat.color;cout<<"Enter the hat price(RM): ";cin>>customer_1.hat.price; cout<<"Hat 2\n";cout<<"Enter customer's Full Name: ";getline(cin,customer_2.fullName);getline(cin,customer_2.fullName);cout<<"Enter customer's age:…arrow_forwardQ No 3. #include <string> using namespace std; class Account { public: Account(string accountName, int initialBalance) { name=accountName; if (initialBalance > 0) { balance = initialBalance; } } void deposit(int depositAmount) { if (depositAmount > 0) { balance = balance + depositAmount; } } int getBalance() const { return balance; } void setName(string accountName) { name = accountName; } string getName() const { return name; } private: string name; int balance; }; Rewrite the following code in correct form. a) Assume the following prototype of destructor is declared in class Time: void ~Time(int); b) Assume the following prototype of constructor is declared in class Employee: int Employee(string, string);…arrow_forwardC ++ Using the following code: enum GradeLevel { FRESHMAN, SOPHMORE, JUNIOR, SENIOR }; struct Student { string first; string middle; string last; GradeLevel year; float GPA; }; Student A0012; // Student ID A0012 Student A0013; // Student ID A0013 A0012.first = "Bjarne"; A0012.last = "Stroustrup"; A0012.GPA = 3.56; A0013 = A0012; A0012.year = SENIOR; A0013.middle = "C++"; A0013.year = static_cast<GradeLevels>(A0012.year - 2); A0013.GPA = floor(A0012.GPA); // floor() rounds down to whole number A0012.middle = A0013.middle.at(0) + "."; What are the contents of the Student variables after this code has executed? Use the chart provided. Who is Bjarne Stroustrup?arrow_forward
- Given a structure named Telco4G as follows struct Telco4G { string telcoProvider; // name of the provider i.e. TelcoA // number of customers // amount of unpaid bills in RM int totalUser; int overdueBills; }; (a) Using struct Telco4G, initialize the structure variable telcol based on the following information: • TelcoA is the telco provider • 2 million number of users Unpaid bills are RM 3.56 million Then, write the syntax to print/display the totalUser structure member in the struct variable Telco4G.arrow_forwardC++arrow_forward} BMI(struct Person* person) { person->BMI = person->weight / (person->height person->height); return person->BMI; } //Q10: Why is the return type char*? char* determineWeightCategory(struct Person* person) {//assumes BMI is known const double UNDERWEIGHT = 18.5; const double NORMALWEIGHT = 24.9; const double OVERWEIGHT = 29.9; } else { //Q11: If the value in person->BMI is equal to 18.5 and person is athletic, what will be //stored in p- //Q12: The first if statement validates against certain conditions. //What are the conditions it is validating against? //HINT: Think about what causes BMI to be less than 0. if (person->BMI weightCategory, "ERROR"); } else if (person->BMI weightCategory, "Underweight"); } else if (person->BMI weightCategory, "Normalweight"); } else if (person->BMI weightCategory, "Overweight"); strcpy(person->weightCategory, "Obese"); return person->weightCategory; //Q13: Why do we return person->weightCategory? } //Q14: Why is provider passed by value?arrow_forward
- use c code to develop a program In this program you will create a structure called class to hold the information of a class in Seneca college’s buildings. The information required for each class is as follows Campus name (like newham or Seneca@york) Building name (like Victor Phillip Dahdaleh Building) floor (like 1 2 3 4 5, …) class code (like DB2109) size of class (40 60 25) has projector (yes/no) has podium (yes/no) has whiteboard (yes/no) The following is the declaration of the structure Struct class{ Char campus[101]; Char building[101]; --- --- } Complete the above structure template based on the list of attributes provided Implement the followinggetClass function that receives a pointer to a vehicle and fills it up with user data. No user input validation is necessary. The user should be properly prompted for each field. Be careful with proper usage of . (dot) operator and -> (arrow) operator as this is the part of the code that gets the mark! void getClass…arrow_forwardC code Blocks Select all of the code segments that are the correct way to define a variable class as an array of 185 personal structures. struct personal { int id; // id numberchar name[80];}; Options: a .personal class[185]; b. struct personal class[185]; c. typedef struct personal classStruct;classStruct class[185]; d. typedef class[185];arrow_forwardCreate a structure called BarcelonaPlayer with the following members.struct BarcelonaPlayer{char name[20];int age;char country[20];char Position[20];double Salary;double Rating;};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 Ptr
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr