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 \(=^{\prime} A^{\prime}\) shoe1.price \(=9.99\) cout \( < < \) shoe \(1 .\) style \( < < " \$^{\prime \prime} < < \) shoe1.price \( < < \) endl shoe \(2=\) shoe 1 shoe2.price \(=\) shoe \(2 .\) price \(/ 9\) cout \( < < \) shoe \(2 .\) style \( < < " \$ " < < \) shoe \(2 .\) price \( < < \) end 1;

Short Answer

Expert verified
Answer: The printed output values are "A $9.99" for shoe1 and "A $1.11" for shoe2.

Step by step solution

01

Analyze the structure definition

struct ShoeType { char style; double price; }; The struct ShoeType has two members - style (a character) and price (a double).
02

Initialize shoe1 and shoe2 objects

ShoeType shoe1, shoe2; Here, two objects of type ShoeType, shoe1 and shoe2, are created.
03

Assign values to shoe1

shoe1.style = 'A'; shoe1.price = 9.99; The character 'A' is assigned to the style member of shoe1, and the value 9.99 is assigned to the price member of shoe1.
04

Print shoe1 values

cout << shoe1.style << " $" << shoe1.price << endl; The style and price of shoe1 are printed, separated by a " \(". The output will be: A \)9.99
05

Assign shoe1 values to shoe2

shoe2 = shoe1; Both the style and price members of shoe2 are assigned the corresponding values of shoe1, which means shoe2.style equals 'A' and shoe2.price equals 9.99.
06

Update shoe2 price

shoe2.price = shoe2.price / 9; The price of shoe2 is divided by 9 and assigned back to shoe2.price. So, shoe2.price = 9.99 / 9 \(\approx 1.11\).
07

Print shoe2 values

cout << shoe2.style << " $" << shoe2.price << endl; The style and updated price of shoe2 are printed, separated by a " \(". The output will be: A \)1.11 To summarize, the output of the given code is: A $9.99 A $1.11

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

Suppose your friend defines an ADT as a C++ class in the way we described in Section \(10.3 .\) You are given the task of writing a program that uses this ADT. That is, you must write the main part of the program as well as any nonmember functions that are used in the main part of the program. The ADT is very long and you do not have a lot of time to write this program. What parts of the ADT do you need to read and what parts can you safely ignore?

(This exercise is for those who have studied the optional section on default arguments.) What output does the following function provide in response to the following calls? void func (double \(x,\) double \(y=1.1,\) double \(z=2.3\) ) \\{ cout \(<

Given the following struct definition: struct \(A\) \\{ int member \(_{-} b\) int member_c; \\}; declare \(x\) to have this structure type. Initialize the members of \(x\) member \(_{-} b\) and member_c, to the values 1 and 2 , respectively. Note: This requests an initialization, not an assignment of the members. This distinction is important and will be made in the text in a later chapter.

When you define an ADT as a C++ class, what items are considered part of the interface for the ADT? What items are considered part of the implementation for the ADT?

Suppose your program contains the following class definition: class Automobile \\{ public: void set_price(double new_price) void set_profit(double new_profit) double get_price(); private: double price double profit; double get_profit(); \\}; and suppose the main part of your program contains the following declaration and that the program somehow sets the values of all the member variables to some values: Automobile hyundai, jaguar; Which of the following statements are then allowed in the main part of your program? hyundai.price \(=4999.99\) jaguar.set_price(30000.97) double a_price, a_profit; \(a_{-}\) price \(=\) jaguar \(.\) get \(_{-}\) price () \(a_{-}\) profit \(=\) jaguar \(\cdot\) get \(_{-}\) profit () \(a_{-}\) profit \(=\) hyundai \(.\) get_profit () if (hyundai \(==\) jaguar) cout \( < < \) "Want to swap cars?"; hyundai = jaguar;

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free