Questions: 11 448

Answers by our Experts: 10 707

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search & Filtering

Consider the class definition below and answer the questions that follow:

class InsurancePolicy
{
public:
InsurancePolicy();
InsurancePolicy(int pNr, string pHolder, double aRate);
~InsurancePolicy();
void setPolicy(int pNr, string pHolder, double aRate);
int get_pNr()const;
string get_pHolder()const;
double get_aRate()const;
private:
int policyNr;
string policyHolder;
double annualRate;
};

(b) Code the interface for a class CarInsurance derived from class
InsurancePolicy (the base class). This class has an additional member
variable, excess. Class CarInsurance also has member functions, get_excess() and set_excess()to return member variable excess and
update member variable excess respectively. The class CarInsurance should
override function setPolicy() in order to update the member variables of
CarInsurance.
Consider the class definition below and answer the questions that follow:

class InsurancePolicy
{
public:
InsurancePolicy();
InsurancePolicy(int pNr, string pHolder, double aRate);
~InsurancePolicy();
void setPolicy(int pNr, string pHolder, double aRate);
int get_pNr()const;
string get_pHolder()const;
double get_aRate()const;
private:
int policyNr;
string policyHolder;
double annualRate;
};

(a) Implement the class InsurancePolicy.
(c) Consider the partial class declaration of an Employee class below:
class Employee: protected Person{
public:
//...
double Rate;
double GetRate() const;
double GetHours() const;
private:
double Hours;
//...
protected:
double Pay() const;
//...
};

double Employee::Pay() const
{
if (DateOfBirth.GetYear() < 1967){
return Hours*Rate;
}
else{
return (Hours*Rate - (Hours*Rate*0.3));
}
}

(iii) Suggest two possible ways of resolving this compilation error.
(c) Consider the partial class declaration of an Employee class below:

class Employee: protected Person{
public:
//...
double Rate;
double GetRate() const;
double GetHours() const;
private:
double Hours;
//...
protected:
double Pay() const;
//...
};

Line 1: cout << E.GetName();
Line 2: cout << E.GetHours();
Line 3: cout << E.Address;
Line 4: cout << E.GetRate();
Line 5: cout << E.Rate;
Line 6: cout << E.Pay();

(ii) Explain why the following implementation of function Pay()would result in a
compilation error.
(c) Consider the partial class declaration of an Employee class below:
class Employee: protected Person{
public:

//...
double Rate;
double GetRate() const;
double GetHours() const;
private:
double Hours;
//...
protected:
double Pay() const;
//...
};

(i) The code fragment below (extracted from a main() function) has three invalid
statements. Write down the line numbers of the invalid statements and explain
why each of these statements is invalid. E is an instance of an Employee
object.

Line 1: cout << E.GetName();
Line 2: cout << E.GetHours();
Line 3: cout << E.Address;
Line 4: cout << E.GetRate();
Line 5: cout << E.Rate;
Line 6: cout << E.Pay();
Consider the following class definitions and answer the questions that follow:

class Date {
public:
Date(int day, int month, int year);
int GetYear() const;
private:
int Day;
int Month;
int Year;
};
class Person{
public:
Person(const string &name, const string &address, const
Date &date);
string GetAddress() const;
string GetName() const;
private:
string Name;
string Address;
Date DateOfBirth;
};
class Customer{
public:
Customer(const string &name, const string &address,
int day, int month, int year,double creditlimit);
void IncreaseLimit(double amount);
string GetName() const;
string GetAddress() const;
void SetBalance(double balance);
double GetBalance() const;
private:
string Name;
string Address;
int DayOfBirth;
int MonthOfBirth;
int YearOfBirth;
double CreditLimit;
double BalanceDue;
};

(b) Implement the constructor for the derived Customer class.
Consider the following class definitions and answer the questions that follow:

class Date {
public:
Date(int day, int month, int year);
int GetYear() const;
private:
int Day;
int Month;
int Year;
};
class Person{
public:
Person(const string &name, const string &address, const
Date &date);
string GetAddress() const;
string GetName() const;
private:
string Name;
string Address;
Date DateOfBirth;
};
class Customer{
public:
Customer(const string &name, const string &address,
int day, int month, int year,double creditlimit);
void IncreaseLimit(double amount);
string GetName() const;
string GetAddress() const;
void SetBalance(double balance);
double GetBalance() const;
private:
string Name;
string Address;
int DayOfBirth;
int MonthOfBirth;
int YearOfBirth;
double CreditLimit;
double BalanceDue;
};

(a) Provide an improved declaration for the Customer class that exploits the
principles of reusability. Provide the interface only.
Overload the +, - and * operators for objects of class Pairs in question 4, as
member functions. Also define the class Pairs as an ADT that uses separate files
for the interface and the implementation. Use separate compilation and the same
program as in question 4 to test these member functions.
The program below contains an incomplete recursive function raised_to_power().
The function returns the value of the first parameter number of type float raised to
the value of the second parameter power of type int for all values of power greater
than or equal to 0.

1. #include <iostream>
2. using namespace std;
3. float raised_to_power( )
4. {
5. if (power < 0)
6. {
7. cout << "\nError - can't raise to a negative power\n";
8. exit(1);
9. }
10. else if ( )
11. return ( );
12. else
13. return (number * raised_to_power(number, power - 1));
14. }
15. main()
16.
17. float answer = raised_to_power(4.0,3);
18. cout << answer;
19. return 0;
20.}

(a) Complete the function header in line 3.
(b) Using the fact that any value raised to the power of 0 is 1, complete the base
case in line 10 and 11.
(c) Why do we need a base case in a recursive function?
(d) What is the purpose of the general case?

A manufacturer uses 1000 bytes as the value of 1K bytes, 1000K bytes as the value of 1MB, 1000MB as the value of 1GB. However, in computer memory, 1KB is equal to 1024 bytes. So the actual storage on a 40GB hard drive is approximately 37.25GB. Write a program that prompts the user to enter the size of the hard drive specified by the manufacturer, on the hard drive box, and outputs the actual storage capacity of the hard drive.

Input

User will need to input the hard drive size in gigabytes. Input the size after the text "Enter hard drive size in giga bytes: ".

Output

The output will be the hard drive size and the actual hard drive storage capacity. The program shall output the hard drive size inputted by the user after the "Hard drive size = ". It'll be followed by the string "Actual hard drive storage capacity = " and the actual hard drive storage capacity computed.


Sample Output

Hard drive size = 704 GB

Actual hard drive storage capacity = 655.651 GB


LATEST TUTORIALS
APPROVED BY CLIENTS