Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN C++, Consider the following declarations: class bagType { public: void set( string, double, double, double, double); void print() const; string getStyle() const; double getPrice()

IN C++,

Consider the following declarations:

class bagType

{

public:

void set( string, double, double, double, double);

void print() const;

string getStyle() const;

double getPrice() const;

void get( double, double, double, double);

bagType();

bagType(string, double, double, double, double);

private:

string style;

double l;

double w;

double h;

double price;

};

bagType newBag; // variable declaration

a. How many members does class bagType have?

b. How many private members does class bagType have?

c. How many constructors does class bagType have?

d. How many constant functions does class bagType have?

e. Which constructor is used to initialize the object newBag?

f. Write the definition of the member function set so that private members are set according to the parameters.

g. Write the definition of the member function print that prints the values of the data members.

h. Write the definition of the default constructor of the class bagType so that the private member variables are initialized to "", 0.0, 0.0, 0.0, 0.0, respectively.

i. Write a C++ statement that prints the value of the object newBag.

j. Write a C++ statement that declares the object tempBag of type bagType, and initializes the member variables of tempBag to "backPack", 15, 8, 20, and 49.99, respectively.

(2) About designing and implementing a C++ class.

Design and Implement a class called personType the following properties:

a. The class personType has four member variables: name (string), age (int), weight (double), height (double)

b. The class personType has the following member functions. (Make each accessor function constant. Can you figure out which functions are accessor functions?)

print outputs the data stored in the member variables with the appropriate titles

setName function to set the name

setAge function to set the age

setWeight function to set the weight

setHeight function to set the height

getName value- returning function to return the name

getAge value- returning function to return the age

getWeight value- returning function to return the weight

getHeight value- returning function to return the height

constructor with default parameters: The default value of name is the empty string "", and the default values of age, weight, and height are 0.

(3) About designing and implementing a C++ class.

Design and implement a class dayType that implements the day of the week in a program. The class dayType should store the day, such as Sun for Sunday. The program should be able to perform the following operations on an object of type dayType:

a. Set the day.

b. Print the day.

c. Return the day.

d. Return the next day.

e. Return the previous day.

f. Calculate and return the day by adding certain days to the current day. For example, if the current day is Monday and we add 4 days, the day to be returned is Friday. Similarly, if today is Tuesday and we add 13 days, the day to be returned is Monday.

g. Add the appropriate constructors.

Save your program as lab5-3-yourName.cpp.

(4) About utilizing an existing (a third party) C++ class in a program.

Some other programmer created a C++ class called die that represents a real life die. You can find the source code (the .h and .cpp files) that implements class die in Lab Filesfolder.

Write a program that will use (include) class die. In your program will declare an array named rolls, of 100 components of type die. Your program should roll each die of the array and find out and then output the highest number rolled.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database And SQL

Authors: Lucy Scott

3rd Edition

1087899699, 978-1087899695

More Books

Students also viewed these Databases questions

Question

l List and briefly discuss five external recruiting sources.

Answered: 1 week ago

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago