Ask Question, Ask an Expert

+1-415-315-9853

info@mywordsolution.com

Ask Programming Language Expert

problem 1

Study the given class specification and answer the problems that follow:
class Person
{
private:
string name;
int yrBorn;
int yrDied;
public:
Person(string, int, int); // initialize all data members
int getYrBorn(); // return year born
int getYrDied(); // return year died
void display(); // display all private data members
int yrLived(); // return the difference between yrDied and yrBorn
};

(a) The access specifiers used in the above class are private and public. describe these access specifiers.

(b) prepare code to implement ALL the methods found in the above class specification.

(i) Constructor

(ii) Assessors

(iii) display method

(iv) yrLived method

(c) prepare a test driver to test ALL the methods in the above class. Use the following test cases.

Test Case 1      Name: Tan Boon Heng
                      Year Born: 1946
                      Year Died: 2010

Test Case 2      Name: Lim Ah Lek
                      Year Born: 1990
                      Year Died: 1992

Test Case 3      Name: Tan Soon Keow
                      Year Born: 1918
                      Year Died: 2009
problem 2

You are required to prepare the declaration and implementation code in separate files. Your submission is expected to reflect this. Study the given class diagrams and additional information and answer the problems that follow:

MagicNumber                            GuessMachine

number: int                               nTimes: int // number of tries
item: string                               winnings: int
                                              nM[6]: MagicNumber
MagicNumber()                          GuessMachine()
setNumber(int): void                  displayPrizes():void
setItem(string): void                  displayMenu():void
getNumber():int                        getInput():int
getItem():string                        checkNumber():void
display(): void                          checkPrize():void
generateNumber():int

Additional Information:

The MagicNumber simulates a dice and generates the number that ranges from 1 to 6. Each number is associated to a prize item such as 1 is associated to “Holiday for 2 to Bali”, 2 is associated to “Dinner for 2 to Swensen Restaurant” etc.

The GuessMachine simulates the number guessing game where the guessed number ranges from 1 to 6. The guessed number is checked against the generated number and the winnings count is increased by 1 if both numbers match. The user “wins” a prize when the number of correct guesses is more than 50% of the number of tries. The prize is randomly selected from the nM[ ] array of type MagicNumber. The number of tries is determined by the choice selected in the displayed menu.

MagicNumber

Method                                             Remarks

MagicNumber()                                Constructor
setNumber(int)                             Mutator of number
setItem(string)                                Mutator of item
getNumber()                                Assessor of number
getItem()                                      Assessor of item
display()                                Display the number and item
generateNumber()               Generate a dice number from 1 to 6

GuessMachine

Method                                               Remarks

GuessMachine()                    Initializes the array nM[6]. Uses a for loop which repeats 6 times to prompt the user to enter the prize item.

displayPrizes()                     Uses a for loop to display the contents of array nM[6] to confirm the initialization of number and item in Constructor code.

displayMenu()                     Display the following menu to prompt the user to enter their choice.

                                        Validates the data and allows the user to re-enter if the data is invalid. The valid range is 1 to 4.
                                                       M A I N M E N U
                                                  =================
                                                          1. $1.00
                                                          2. $2.00
                                                          3. $3.00
                                                          4. Exit
                                              Enter choice (1,2, 3 or 4):
getInput(): int

Prompts user to enter a choice based on the displayed menu. Set the data member, nTimes according to the below look-up table and return nTimes.

Number        No. of times
1                     5
2                    10
3                    20
4                     0

checkNumber()

Declare an instance of MagicNumber. Uses a loop to repeat nTimes to allow the user to enter a number and invoke the generateNumber method of MagicNumber. If the number entered by the user matches the generated number, increase the winnings count by 1.
checkPrize()

The user wins a prize if the number of times guessed correctly is more than 50% of nTimes. The prize is determined by a generated number and this number is used to index into the array of magicNumbers to obtain the prize item.

(a) prepare code for the class specification:

(i) MagicNumber

(ii) GuessMachine

(b) prepare code to implement ALL the methods found in MagicNumber class.

(c) prepare code to implement ALL the methods found in GuessMachine class.

(d) prepare a test driver to test ALL the methods that you have implemented in Part (b) and (c). Instantiate one instance of GuessMachine.

problem 3

Study the following class diagram, additional information and answer the problems that follow:

    MovieTicket

movieName: string
TicketPrice: double
TicketsSold: int
donation[100]: double
totalCnt: int
MovieTicket();
getName():string
getTicketPrice():double
getnoOfTicketsSold():int
setName(string): void
setTicketPrice(double): void
setnoOfTicketsSold(int): void
computeDonation(int): void
prepareFile():void

Additional Information:

MovieTicket is a class written to fulfill the requirements of making 100 donations to charity from the ticket sales. The donation is derived from 10% of the ticket sales. The donations are written to a file.

Method                                      Remarks

MovieTicket();                            Constructor
getName():string                         Returns the movie name
getTicketPrice():double                 Returns the ticket price
getnoOfTicketsSold():int               Returns the number of tickets sold
setName(string): void                   Sets the movie name
setTicketPrice(double): void          Sets the ticket price
setnoOfTicketsSold(int): void         Sets the number of tickets sold
computeDonation(int): void           Compute donations from ticket sales and store each value in the array, donation[100].
prepareFile():void                           Prompts the user to enter the file name, performs the necessary file processing and uses a loop to traverse the array, donation.

(a) prepare the class specification for MovieTicket.

(b) prepare code to implement the following for MovieTicket:

(i) Constructor, Assessors and Mutators

(ii) computeDonation method

(iii) prepareFile method

(c) prepare a test driver to test ALL the methods written in Part (b). The program uses a loop to repeat 100 times to obtain input (movie name, tickets sold and ticket price) from user and invokes the respective methods to set the values and computes the donation. After the loop, the contents of donation array is written to a file using the prepareFile method. Include a screen output in your submission.

problem 4

Study the given hierarchical class diagram and additional information, and answer the problems that follow:

Sale

Company: string
unitPrice: double
qty: int
salesAmt: double
Sale(string, double, int);
getCompany():string;
getUnitPrice():double;
getQty():int;
getSalesAmt():double;
computeRevenue():double;

         ↑

HardwareSale

installFee: double
hWSale(string, double, int, double)
computeRevenue():double

Additional Information

Sale

Sale(string, double, int);        Constructor  that initializes the respective data members to the pass in values. salesAmt is set to 0.
getCompany():string;            Returns the company
getUnitPrice():double;           Returns the unit price
getQty():int;                       Returns the quantity
getSalesAmt():double;          Returns the sales amount
computeRevenue():double;    Sets sales amount = unit price *quantity. Returns this computed value.

HardwareSale

hWSale(string, double, int, double)  Invokes the base class constructor and sets install fees accordingly
computeRevenue():double              Sets sales amount = unit price * quantity + install fees

(a) prepare the class specification and code to implement the following classes, fulfilling the given requirements:

(i) Sale (base class)

(ii) HardwareSale(derived class)

(b) prepare a test program to instantiate one instance of each class. Use the following test data. Include a screen output in your submission.

Class                  Company          Unit Price          Quantity      Install Fee
Sale                 SAT Company        123.00                  5                -
HardwareSale     RX Company          127.00                  5          1000.00

(c) The method, computeRevenue appears in both classes. Is this overriding or overloading of methods? describe what changes you would make to the code to enable dynamic binding.

Programming Language, Programming

  • Category:- Programming Language
  • Reference No.:- M91905

Have any Question? 


Related Questions in Programming Language

The exercise for this week is to write a class that

The exercise for this week is to write a class that simulates managing a simple bank account. The account is created with an initial balance. It is possible to deposit and withdraw funds, to add interest, and to find out ...

Assignmentan office building has 5 floors 4 levels above

Assignment An office building has 5 floors (4 levels above ground and a basement at level 0). There are 8 offices per floor, labeled A - H. This program will maintain data about the occupant type of employees in each off ...

Assignmentreference this assignment is an object oriented

Assignment Reference: This assignment is an object oriented version of the In-class assignment. The functionality supported for a single vehicle in ICA 01 would be extended to multiple vehicles using a single class Car, ...

Question 1a class is like a blueprint which you use to

Question 1 A class is like a blueprint which you use to create objects. An object is an instance of a class. It's a thing that you made out of a speci?c class. Basically, object and instance mean the same, but the word i ...

Lab assignmentwe begin our investigation of object-oriented

Lab Assignment We begin our investigation of object-oriented programming by creating an object-oriented program with a class called Employee. You will create two objects based on the Employee class, along with a class th ...

Suppose the heap consists of exactly the nine cars on three

Suppose the heap consists of exactly the nine cars on three trains shown in given figure (i.e., ignore the ellipses). Object o in car 11 has references from cars 12, 23, and 32. When we garbage collect car 11, where migh ...

Lab- forms loops and stringssubmission Lab- Forms, Loops and Strings Submission

Lab- Forms, Loops and Strings Submission Instructions How Please submit your lab report to the Lab4_Submission folder in Moodle. When Labs are due in 1 week on Feb. 13, 2014 Exercises: Goals: - Gain more hands-on with us ...

Programming assignmentthis question has two parts a and

Programming Assignment This question has two parts (a) and (b): Develop a program to read in five exam-scores (in the range of 0-100) of a student in HIST220 class. (a) You program should compute and store in memory the ...

Assignment research projectwrite an overview of any two of

Assignment: Research Project Write an overview of *any two* of the below topics. Each overview should be between one half and one full page long. You should use a minimum of two sources for each overview; make sure to re ...

1 write a pay-raise program that requests a persons first

1. Write a pay-raise program that requests a person's first name, last name, and current annual salary, and then displays their salary for next year. People earning less than $40,000 will receive a 5% raise, and those ea ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

WalMart Identification of theory and critical discussion

Drawing on the prescribed text and/or relevant academic literature, produce a paper which discusses the nature of group

Section onea in an atwood machine suppose two objects of

SECTION ONE (a) In an Atwood Machine, suppose two objects of unequal mass are hung vertically over a frictionless

Part 1you work in hr for a company that operates a factory

Part 1: You work in HR for a company that operates a factory manufacturing fiberglass. There are several hundred empl

Details on advanced accounting paperthis paper is intended

DETAILS ON ADVANCED ACCOUNTING PAPER This paper is intended for students to apply the theoretical knowledge around ac

Create a provider database and related reports and queries

Create a provider database and related reports and queries to capture contact information for potential PC component pro