经典案例 > C/C++代写 >

Homework 2

100 Points

2D Arrays


22B_H_2A.cpp (find and fix errors: print a table) 22B_H_2B.cpp (find and fix errors: quiz average) 22B_H_2C.cpp Project: Triangle (see next page)


Grading

Program 2A 15

Program 2B 20

Program 2C

1.

main()

– 5

2.

The readTriangle function

– 15

3.

The printTriangle function

– 10

4.

Find path

– 15

5.

Print path

– 15

6.

Self Assessment Report

– 5


Self Assessment Report: Write a short report, ( see 22B_H_2Report.doc form) briefly explaining your code and containing an assesment of your implementation based on the above grading criteria.


Run each programonce and save the output at the end of the source file as a comment. Compress the source files, input and output files (if any), and the report, and upload the compressed file: 22B_LastName_FirstName_H2.zip


Next Page


Project: Triangle

(Figure 1)


7

3 8

8 1 0

2 7 4 4

4 5 2 6 5


Figure 1 shows a number triangle. Write a program that calculates the highest sum of numbers passed on a route that starts at the top and ends somewhere on the base. Each step can go either diagonally down to the left or diagonally down to the right. The number of rows in the triangle is >1 but <=100. The numbers in the triangle, all integers, are between 0 and 99.


Input Data: Data about the number of rows in the triangle are first read from the input file. In our example, the input file appears as follows:

5 // This triangle has 5 rows

7

3 8

8 1 0

2 7 4 4

4 5 2 6 5


Output Data

  1. Display the triangle if and only if its size is <= 15, as shown below:

    Triangle size = 5

    7

    3 8

    8 1 0

    2 7 4 4

    4 5 2 6 5

  2. Display the highest sum (30 in our example) and the path (row, column and

    value) as shown below.

    ( 0, 0) - 7

    ( 1, 0) - 3

    ( 2, 0) - 8

    ( 3, 1) - 7

    ( 4, 1) - 5

    === 30

  3. (Optional) In addition to the above output, if the number of rows <= 15 display the path a second time as shown below.


|7|

|3 _|

|8 _ _|

|_ 7

_ _|

|_ 5

_ _ _|


Highest sum = 30.


Algorithm – will be discussed in class.

51作业君