MTE 121 Assignment 4 Fall 2021

MTE 121 Assignment 4 Fall 2021

Questions 1 and 2 of the assignment are to be completed in pairs, while question 3 (Learn Quiz) is to be
completed individually. You will be randomly assigned a partner in your tutorial section to work with for
the week.
Experience with programming before starting MTE 121 varies.
If you have one partner who is noticeably more experienced than the other, try having the
inexperienced person at the keyboard typing the code with the more experienced person offering
suggestions that help teach the person with less experience. Teaching another person is a great way to
get better at something!
If both partners have similar experience, try alternating who is typing the code, the driver, and who is
offering suggestions, the navigator. (If you are curious, look up pair programming to find a description of
this technique as it is used for agile programming.)
Some pairs will have one person remote, and one person in the WEEF lab. Before you get started,
discuss how you are going to share the files and communicate while working on the assignment
together.
Deliverables
• In this assignment you will:
o Work with nested loops and if-statements
o Solve a substantial problem
o Format output
• There are three deliverables for this assignment:
o Question 1
o Question 2
o Question 3 – Assignment 4 quiz (available on UW Learn)

Question 1: Water Taxi
Understanding the problem
The James Bufét Water Taxi Company uses a boat on the Caribbean Sea to transport people and goods
from the main dock to various islands and ports. The service charge for a trip is $15.00 for each stop and
$2.60 per kilometer of travel. Some people are regular customers and granted a VIP card to receive a
25% discount of their trip cost.
A GPS records the (x, y) position for each stop.
All trips begin at the main dock (0,0). Each leg of the trip is made in a straight line of the shortest
distance between stops (including the main dock).
A file called “taxi.txt” contains the records for all the trips made in August. Each line in the file contains
the information for one customer. The data on each line is formatted as follows:
• A binary (0 or 1) value that indicates whether the customer has a VIP card or not. 1 = VIP while 0
= not VIP.
• The number of stops, not including returning to the main dock.
• Pairs of (x,y) coordinates for each of the stops.
Here are the first three lines of the “taxi.txt” file:
0 1 0 10.2
1 2 1 -2 4 3
0 4 0 -3 4 -3 -7.5 2.6 5.1 6


To help verify your understanding of the data file format, here is an explanation of the second
customer’s one line of data in the file: 1 2 1 -2 4 3

• The customer has a VIP card and hence should receive a 25% discount on their trip cost.
• There were two stops:
o Leg 1 covers distance from the main dock at (0, 0) to the first stop at (1, -2)
o Leg 2 covers distance from the first stop at (1, -2) to the second stop at (4, 3)
Cost calculation
Leg Distance (km) Cost for the leg
Leg 1 2.236 2.236 * $2.60 + $15 = $20.81
Leg 2 5.831 5.831 * $2.60 + $15 = $30.16
Return Trip 5 5 * $2.60 = $13.00
Total Cost $63.97
Trip Cost after discount $47.98
What you need to do
Warning: this question is very difficult if you don’t first design your code and thoroughly understand the
problem itself.
Your program is to generate a report file summarizing the taxi’s earnings for the month of August. The
report must contain the following information on each line:
• Trip number
• VIP or not (0 = no, 1 = yes)
• Number of stops (not including return to main dock)
• Total distance travelled for the trip
• Total cost charged to the customer
• Cumulative distance travelled during the month (taxi odometer reading after it was reset to 0 on
day 1 of each month)
• Cumulative cost charged to all customers during the month (money the taxi driver collected for
the month)
The report is to display only the lines for the first four trips and then every tenth thereafter (i.e. the 14th
,
24th, etc.). Format your output using the setw() and setprecision() functions in a table similar to the one
shown below. Remember to include the library.
trip# VIP stops tripDist tripCost totalDist totalCost
1 0 1 20.40 68.04 20.40 68.04
2 1 2 13.07 47.98 33.47 116.02
3 0 4 40.72 165.86 74.18 281.88


The report must also include the following data at the bottom:
• cumulative distance travelled for all of August
• cumulative amount collected from all customers for all of August
• the length of the longest trip
• The cost of the least expensive trip

What to submit in Crowdmark
Submit your code and the contents of the output file obtained from processing the input file “taxi.txt” in
/Block comments/ at the end.

Question 2: Tree Drawing
You are asked to write a C++ program that draws a tree with a trunk of four asterisks and a base of n
asterisks where n is an odd number between three and nine. The tree structure is shown in the sample
outputs below.
Your program must verify the base number (n) being an odd number between three and nine with the
most appropriate loop.
Sample Output 1
How many asterisks does the base of the tree have? 2
Invalid input! Try again.
4
Invalid input! Try again.
11
Invalid input! Try again.
3

*
***
*
*
*
*

Sample Output 2
How many asterisks does the base of the tree have? 5

*
***
*****
 *
 *
 *
 *

What to Submit in Crowdmark
Your code and include adequate test cases to demonstrate that all features of the program are working
properly in /Block comments/ at the end.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值