Sale!

CSE 241 Programming Assignment 1 solved

Original price was: $35.00.Current price is: $35.00. $21.00

Category: You will receive a download link of the .ZIP file upon Payment

Description

5/5 - (1 vote)

For this assignment, you are expected to write an interactive program which, according to the user input, creates
dynamic responses and do simple calculations.
A compound object will be defined interactively and you program will keep track of a simple property and return a
result based on the composition of the object.
Example:
Suppose that you want to calculate the total cost of a bicycle. In this case your compound object is a bicycle. A
bicycle has many parts and some of the parts are also compound objects individually. So, a hierarchical structure
can be used in order to model such a compound object. You can visualize it as a tree. Nodes are the parts and the
children of a particular node are the parts which make up the part associated with that node.
Bicycle x 1
Wheel x 2
Frame x 1
Rim x 1 60.0
Spoke x 28 12.0
Hub x 1
Gear x 6 25.0
Axle x 1
Bolt x 5 0.1
Nut x 7 0.15
Rearframe x 1 170.0
Frontframe x 1
Fork x 2 21.5
Handle x 1 12.0
Price
Figure 1: Composition of a bicycle
Figure 1 shows parts of a bicycle. A bicycle can be described as an object which consists of 2 wheels and a frame.
We can create a more detailed description by including the description of the individual parts, wheel and frame. A
description includes number of the parts, part name and, if no further description is needed, prices of the part or
parts.
Your program does not know anything about the compound object. Expectation is either there is a compound
object which can be specified by its parts or there is a simple object which can be specified by its property
For this example, the propery is the price of an object. Your program will ask questions to the user and eventually
calculate the total price of the bicycle the user described.
Below is a simple dialog which the user describes the object ‘bicycle’ to the program:
> Define the object:
> Bicycle
1
> What is Bicycle?:
> 2*Wheel+1*Frame
> What is Wheel?:
> 1*Rim+28*Spoke+1*Hub
> What is Rim?:
> 60.0
> What is Spoke?:
> 12.0
> What is Hub?:
> 6*Gear+1*Axle
> What is Gear?:
> 25.0
> What is Axle?:
> 7*Nut+5*Bolt
> What is Nut?:
> 0.15
> What is Bolt?:
> 0.1
> What is Frame?:
> 1*Rearframe+1*Frontframe
> What is Rearframe?:
> 170.0
> What is Frontframe?
> 1*Fork+1*Handle
> What is Fork?:
> 21.5
> What is Handle?:
> 12.0
> Total cost of Bicycle is 1320.1
Remarks
• You will construct the required data structure on-the-fly.
• You can assume the maximum length of a user input will not exceed 100 characters.
• There may be spaces in between the terms of the user input. Below is a valid input:
1* Rearframe + 1 * Frontframe
• Do not submit your code without testing it with several different scenarios. Bicycle and its structure are
presented as an example only. Your program should run if the user tries to describe another object. For
example: A car engine, a meal, etc. . .
• You are not allowed to use classes. However, you can use c structs, unions, arrays, c strings, pointers, dynamic
memory allocation, etc. . .
• Write comments in your code.
• If your code does not compile you will get 0
• Do not share your code with your classmates.
Turn in:
A complete C++ program which can be compiled using the following command:
g++ assignment_1_fullname_id.cpp -o assignment_1_fullname_id
If your program requires additional compile and link options, state those requirements at beginning of your source
code as comment.
2
Late Submission
• (0,24] hours: -20%
• (24,48] hours: -40%
• (48,72] hours: -60%
• (72,-) hours: -100%
3