首页 > > 详细

辅导SOF103编程、讲解Programming语言程序、c++编程设计调试辅导留学生 Statistics统计、回归、迭代|辅导R语言程序

SOF103 C and C++ Programming
Lab Exercise 4
Arrays
Due Date: 8 November 2020
Late Submission Policy:
 Up to 4 hours late:10% penalty
 Up to 2 days late: 25% penalty
 More than 2 days late: 50% penalty
 No submission will be accepted after 4 days of the specified deadline: 100%
penalty
Part A: Review Questions
Instruction: Answer the following review questions
1. Write C++ statement to accomplish each of the following:
a) Display the 7th element of array a.
b) Input value into the 3rd element of array a.
c) Calculate the sum of the first and second element of array a, then store it as the third
element.
d) Print the element stored at the 3rd row, 2nd column of a 2D array table.
e) Store the user input into the 5th element of array a.
2. Write C++ statement to accomplish each of the following:
a) Calculate the sum of all (5) elements in array a.
b) Initialize an integer array a with size of 10 as number from 1 to 10.
c) Print the following character array in reverse order.
d) Declare a Boolean array b with size of 5 and then read 5 integers from user. If the
number is positive, store a true into it, otherwise store a false.
Part B: Programming Practice
1. One interesting application of computers is drawing graphs and bar charts (sometimes
called “histograms”). Write a program that reads five numbers (each between 1 and
10). For each number read, your program should store the number in an integer array.
Next, for every number in the array elements, print a line containing that number of
adjacent asterisks. For example, if your program reads: 2 3 5 8 4, it should print:
Element Value Histogram
0 2 **
1 3 ***
2 5 *****
3 8 ********
4 4 ****
2. Given that array data is initialized as:
int data[9] = {10, 11, 57, 22, 59, 33, 97, 26, 9};
Write a program that read an integer and then search for the same number in the array, if the
number is found, the program should output the index of the number, otherwise, the program
should tell user that the number is not in the array.
Additional challenge: solve this problem without using any loop
Hint for challenge: 57 - 3 = 54, 22 - 4 = 18
Example:
3. Use single-subscripted array to solve this problem. Write a program that reads 10 characters
from user, then reverse the order of a part of the input. Try to use smallest possible size of extra
memory to solve this problem.
Example:
4. Ten students were asked to rate the quality of the food in the student cafeteria on a scale of 1
to 3 (1 means poor, 2 means average, 3 means good). Write a program to read the responses
of the 10 students into an array and summarize the frequency of the rating. An example is
shown below.
5. Use a single-subscripted array to solve the following problem. Read in 10 numbers, each of
which is between 10 and 100, inclusive. As each number is read, print it only if it is not a
duplicate of a number already read. Provide for the “worst case” in which all 10 numbers are
different. Use the smallest possible array to solve this problem.
Enter the 10 responses: 1 3 2 3 2 1 3 2 1 2
Rating Frequency
1 3
2 4
3 3
6. Store the multiplication table for number from 1 to 12 as a 2 dimensional array then print it.
Example:
7. Table 1 is the summary of examination marks for three students. The students are labelled as
student[0], student[1] and student[2]. The subjects are labelled as subject[0], subject[1],
subject[2] and subject[3]. Use a two-dimensional array to store the students’ marks in the table
format. Then, find the lowest mark, the highest mark and the average mark for student0,
student1 and student2.
subject[0] subject[1] subject[2] subject[3]
student[0] 78 60 79 88
student[1] 85 80 77 91
student[2] 89 78 81 75
Table 1: Student marks and subjects
An example of the program output is:
8. A company has three salespeople (labelled 1 to 3) who sell two different products (labelled 1
and 2). Write a program to enter the sales according to products by each salesperson. Then,
summarize the total sales by printing a table that includes the total sales to the right and to the
bottom of the table. As an example,
Enter sales by salesperson 1 (product1 product2): 120 135
Enter sales by salesperson 2 (product1 product2): 230 100
Enter sales by salesperson 3 (product1 product2): 250 150
Product 1 Product 2 Total
Salesperson 1 $120.00 $135.00 $255.00
Salesperson 2 $230.00 $100.00 $330.00
Salesperson 3 $250.00 $150.00 $400.00
Total $600.00 $385.00 $985.00
subject[0] subject[1] subject[2] subject[3]
student[0] 78 60 79 88
student[1] 85 80 77 91
student[2] 89 78 81 75
Lowest mark: 60
Highest mark: 91
The average mark for student 0 is 76.25
The average mark for student 1 is 83.25
The average mark for student 2 is 80.75

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!