Lab Report 4 (312023705003)
Lab Report 4 (312023705003)
1. You have to hand in a Lab report, all source code, and snapshots
of program output or results before the deadline. If you miss the
deadline, just get half mark for this assignment.
2. If anybody copies any code from another student, both of them get
0 mark.
3. Lab Target
(1) To understand and practice file input and output
(2) To understand and practice decision making structure
4. Tools
Operation System: : Not limited
Programming Language: C++ Programming Language
Textbook: Starting Out with C++ Early Objects
5. Tasks (After finish the following tasks, hand in Lab Reports, all source code,
and snapshot of running results)
5.1 Task One
Every student has the information as below: studentID(integer),
math(float),chinese(float),computer(float) . Make a program to input n(n=2~4)
students' information via the keyboard and writes the achievement information of
n students in a file named as "score.txt".
Write a program that asks for the number of units purchased and computes the total
cost of the purchase. Input Validation: Make sure the number of units is greater
than 0.
5.4 Task Four: Write a program that displays the following menu (use switch...case
structure):
Geometry Calculator
1. Calculate the Area of a Circle
2. Calculate the Area of a Rectangle
3. Calculate the Area of a Triangle
4. Quit
Enter your choice (1-4):
If the user enters 1, the program should ask for the radius of the circle and then
display its area. Use 3.14159 for . If the user enters 2, the program should ask
for the length and width of the rectangle, and then display the rectangle’s area. If
the user enters 3, the program should ask for the length of the triangle’s base and
its height, and then display its area. If the user enters 4, the program should end.
Input Validation: Display an error message if the user enters a number outside the range of
1 through 4 when selecting an item from the menu. Do not accept negative values for the
circle’s radius, the rectangle’s length or width, or the triangle’s base or height.
The execution of the program may look like the following:
Conclusion
In conclusion, these exercises were really challenging for me and at the same time
interesting because of using new knowledges in practice. Especially, the exercise 3
was useful to understand the “switch case” very well. Additionally, opening the txt