Programming Languages Homework Void Producttypesetdiscountdouble Discount Else Discount Double Producttypegetdiscount Const Return Discount Void Housetypesetstring

subject Type Homework Help
subject Pages 14
subject Words 66
subject Authors D. S. Malik

Unlock document.

This document is partially blurred.
Unlock all pages and 1 million more documents.
Get Access
page-pf1
61
}
h.
void productType::setDiscount(double d)
{
if (d >= 0.0)
}
12.
a.
void houseType::set(string s, int bed, int bath, int cg,
int yb, int fs, double pr, double tx)
{
}
b.
void houseType::print() const
{
cout << "Style: " << style << endl;
cout << "Number of Bedrooms: " << numOfBedrooms << endl;
}
c.
houseType::houseType(string s, int bed, int bath, int cg,
int yb, int fs, double pr, double tx)
{
style = s;
page-pf2
62
yearBuilt = yb;
finishedSquareFootage = fs;
price = pr;
tax = tx;
}
d. newHouse.print();
13.
a. 14
14.
a.
void temporary::set(string d, double f, double s)
{
description = d;
if (f >= 0)
return first * second;
else if (description == "circle")
page-pf3
return 3.1416 * first * first;
else if (description == "sphere")
<< ", area = " << manipulate() << endl;
else if (description == "circle")
cout << ": radius = " << first
<< ", area = " << manipulate() << endl;
else if (description == "sphere")
cout << ": radius = " << first
d.
temporary::temporary(string d, double f, double s)
e.
void temporary::get(string& d, double& f, double& s)
void temporary::setFirst(double f)
{
if (f >= 0)
page-pf4
}
15. The statement in Line 1 creates object1 and initializes the instance variables of this object
to "", 0, 0, that is, object1.description = "";, object1.first = 0.0;,
and object1.second = 0.0;. The statement in Line 2 creates object2 and initializes
16.
-- invalid shape.
page-pf5
65
19.
20. 3510862895423079232: The number of digits----
21. a. personType student("Buddy", "Arora");
22. If you do not want the user of a class to manipulate or access certain members of a class
directly, such as instance variable, you declare them private. If a member of a class, such
23. A constructor is a member of a class and it executes automatically when a class object is
25. A destructor is a member of a class and if it is included in a class, it executes automatically
26. ac.
page-pf6
66
class stockType
{
double getCurrentPrice() const;
void setLowPriceOfTheDay(double lowP);
double getLowPriceOfTheDay() const;
void setHighPriceOfTheDay(double highP);
double getHighPriceOfTheDay() const;
string symbol;
double currentPrice;
double lowPriceOfTheDay;
double highPriceOfTheDay;
double previousDayClosingPrice;
double fiftyTwoWeeksHigh;
double fiftyTwoWeeksLow;
};
d.
void stockType::print() const
page-pf7
<< endl;
<< endl;
cout << "Previous Day Closing Price: "
<< previousDayClosingPrice << endl;
cout << "Fifty Two Weeks High: " << fiftyTwoWeeksHigh
<< endl;
cout << "Fifty Two Weeks Low: " << fiftyTwoWeeksLow << endl;
}
void stockType::setStockName(string n)
{
name = n;
}
currentPrice = 0.0;
}
double stockType::getCurrentPrice() const
{
return currentPrice;
}
void stockType::setLowPriceOfTheDay(double lowP)
{
if (lowP >= 0.0)
page-pf8
{
previousDayClosingPrice = 0.0;
}
double stockType::getPreviousDayClosingPrice() const
{
return previousDayClosingPrice;
}
void stockType::setHighPriceOfTheDay(double highP)
{
if (highP >= 0.0)
}
double stockType::getFiftyTwoWeeksHigh() const
{
return fiftyTwoWeeksHigh;
}
void stockType::setFiftyTwoWeeksLow(double fTWL)
{
if (fTWL >= 0.0)
fiftyTwoWeeksLow = fTWL;
page-pf9
}
double lowP, double highP, double preDayClP,
double fTWH, double fTWL)
{
name = n;
symbol = sym;
if (curP >= 0.0)
highPriceOfTheDay = 0.0;
if (preDayClP >= 0.0)
previousDayClosingPrice = preDayClP;
else
previousDayClosingPrice = 0.0;
}
28. a. equal and the constructor with default parameters.
b.
void myClass::set(int x, int y)
{
num1 = x;
num2 = y;
}
page-pfa
70
return (num1 + num2) / x;
else
return num1 -num2 + x;
}
myClass::myClass(int x, int y)
{
set(x, y);
}
c.
#include <iostream>
#include "myClass.h"
using namespace std;
int main()
{
void set(int x, int y) {num1 = x; num2 = y)}
void print() const;
//Function to output the values of num1 and num2;
int compute(int x);
//Function to return a value as follow:
page-pfb
71
29.
a. myClass::count = 0;
b. myClass.incrementCount();
c. myClass.printCount();
d.
{
x = a;
}
g.
The statements in Lines 1 and 2 are valid.
The statement in Line 3 should be: myClass::printCount();.
h.
5
30.
page-pfc
#include <iostream>
#include "die.h"
using namespace std;
{
num = rolls[j].getNum();
rollCount[num - 1]++;
}
for (int j = 0; j < 6; j++)
cout << (j + 1) << " " << rollCount[j] << endl;
for (int j = 0; j < 6; j++)
{
page-pfd
Chapter 11
2.
3. Some of the member variables that can be added to the class employeeType are:
department, salary, employeeCategory (such as supervisor and president), and
class employeeType: public personType
{
};
4. a. The functions that can be added to the class sphereType are volume and surfaceArea. No
b.
page-pfe
{
public:
c.
double sphereType::volume()
}
5. a. The base class is shoe and the derived class is runningShoe.
6. a.The base class is house and the derived class is twoStory.
7. Private members of the object newCylinder are xCoordinate, yCoordinate, radius, and
8.
void circle::print() const
{
cout << "x-coordinate: " << xCoordinate << endl;
cout << "y-coordinate: " << yCoordinate << endl;
cout << "radius: " << radius << endl;
}
page-pff
75
xCoordinate = x;
else
xCoordinate = 0.0;
}
radius = 0.0;
}
circle::circle(double x, double y, double r)
void cylinder::print() const
{
page-pf10
double cylinder::volume()
double cylinder::area()
{
return 2 * circle.area() + 2 * 3.1416 * getRadius() * height;
}
cylinder::cylinder()
{
9. Omit the word class before employee. The first statement should be:
class hourlyEmployee: public employee
In the third line replace :: with :. This statement should be
10. a. Omit semicolon at the end of the first statement. Omit const from the heading of the function
power because it manipulates data, so it cannot be a constant function. Insert semicolon after }.
A correct definition of class derivedFromTemp is:
class derivedFromTemp: public temp
{
page-pf11
77
//0.0, and 0.0, respectively.
};
b. The function setPay of the class hourlyEmployee overloads the function setPay of the
c.
void hourlyEmployee::setData(string n, string d, int a,
double p, double hrsWk, double payRate)
{
employee::setData(n, d, a, p);
void hourlyEmployee::setHoursWorked(double hrsWk)
{
if (hrsWk >= 0)
hoursWorked = hrsWk;
else
hoursWorked = 0.0;
double hourlyEmployee::getHourlyPayRate() const
{
return hourlyPayRate;
page-pf12
}
}
11. a.
void print() const;
12. In overriding a public member function of a base class, in the derived class, the corresponding function
must have the same name, number, and types of parameters. In other words, the name of the function
13. First a constructor of class one will execute, then a constructor of class two will execute, and
finally a constructor of class three will execute.
15. a. Invalid. z is an instance variable of the derived class, it cannot be accessed by the members of
the class smart.
b. Invalid. secret is a private member of the class smart. It cannot be accessed directly
page-pf13
16. a.
smart::smart()
{
x = 0;
y = 0;
}
}
17. Between the preprocessor directive #ifndef and #endif. The definitions of the classes one
and two can be placed between these directives as follows:
19. In a private inheritance, the public members of the base class are private members of the
derived class. They can be directly accessed in the derived class. The protected members of
page-pf14
80
member functions (and friend functions) of the derived class. The private members of the
base class are hidden in the derived class. They cannot be directly accessed in the derived class.
They can be accessed by the member functions (and friend functions) of the derived class
through the public or protected members of the base class.
20. In a protected inheritance, the public members of the base class are protected members of
the derived class. They can be accessed by the member functions (and friend functions) of the
21. In a public inheritance, the public members of the base class are public members of the
derived class. They can be accessed by the member functions (and friend functions) of the
22. The private members of a class cannot be directly accessed by the member functions of the
23. The protected members of a base class can be directly accessed by the member functions of

Trusted by Thousands of
Students

Here are what students say about us.

Copyright ©2022 All rights reserved. | CoursePaper is not sponsored or endorsed by any college or university.