Download Exercise1

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
First Assignment, C++ programming
Laboratory Tutors: Y. K. Choi (27888639, [email protected]) and Cyril Tse
(27889800, [email protected])
Deadline:
Before 8th July 2002, 5:00 p.m., either hand in to your laboratory tutor(s) in week
four during laboratory session or put it into your laboratory tutor’s pigeon hole
Contribution:
30% of continuous assessment (15% of overall mark)
Procedure of selecting the questions: total four questions
1)
2)
3)
4)
The first one is a compulsory question regardless of your student
identity number.
For questions 2 to 4, chose the one that is related to your last digit of
your student identity number. It is based on this: Divide your last digit
by 3, if the remainder is:
Remainder Question number
2
0
3
1
4
2
For questions 5 to 6, chose the one that is related to your digit before
the last one of your student identity number. If the number is odd,
choose question 6, else question 5.
For questions 7 to 9, chose the one that is related to the summation of
the last two digits of your student identity number. It is based on this:
Divide the result by 3, if the remainder is:
Remainder Question number
9
0
8
1
7
2
Requirement:
1)
For each question, you should cover the following three parts:
i)
Your code with comments
ii)
Your test input/output, you have to capture the DOS screen
ii)
Not more than half a page on your explanation on how you
design/write for each program.
We also base on the above to mark your assignment.
1
Question 1:
6 marks (1 mark for each scenario with explanation, 1
mark for each input/output screen)
Questions (2 – 4): 3 marks
Questions (5 – 6): 3 marks
Questions (7 – 9): 3 marks
Total 15 marks:
2)
You should submit your hardcopy with the following cover page
Assignment One: C++ Programming (DCO10105)
Name:
Chan Tai Man
Student identity: 123456
Questions chosen: Questions 1, 3, 6 and 9 (must match your student
identity number)
Date:
Group:
I declare that this assignment is my own work and did not copy from any
classmate(s).
I will give you zero mark if you do not write down your student identity
number. Deduce marks if your identity number does not match with the
question number.
Your
work
Questions
1)
Use your last two digits of student identity and define them in the
following code (must minus 5 for each statement). Write down the
remaining codes using the Boolean operations such that it will display true.
For example, your student identity is 50512363.
void main(){
int i = 6 - 5;
int j = 3 - 5;
…
…
Must - 5
You should write the following:
2
i)
ii)
iii)
a single statement that consists of ANDs only
a single statement that consists of ORs only
a single statement that consists of NOTs only
You can use the above variables i and j many times in each single
statement.
2)
Design and implement a program that accepts your student identity. The
program should display the sum of each number. For example, if your
student identity is 50515111, the result is 19.
3)
Design and implement a program that accepts you last number of student
identity and displays the output as follows:
1 2
1 2
1 2
..
1 2
12
1
3 4 5… n
3 4 …n-1
3 n–2 n-1
3
4)
Design and implement a program that accepts your names that determines
the number of strings and average string length. For example, if your name
is “Chan Tai Man”, your program should display 10 and average string
length is 3.3.
5)
Implement a program that accepts your last student identity and displays
these values in histograms using $. For example, if your last three digits
are 567, it will display:
5: $$$$$
6: $$$$$$
7: $$$$$$$
“accept”
means input,
not hardcode
6)
Design and implement a program that prompts a filename which contains
your names. The program then counts the numbers of occurrences of your
name. (Hint: You should create this file using Notepad with your names
in this file.)
7)
Write a float function called GetArea() that is called by your main()
program to obtain the area of a circle with a radius that is input by you.
Your program will display the result on the screen. Your input to the main()
is an integer.
3
8)
Write an integer function called GetArea() that is called by your main()
program to obtain the area of a sphere with a radius that is input by you.
Your program will display the result on the screen. Your input to the main()
is a floating-point number.
9)
Write a floating function called GetVolume() that is called by your main()
program to obtain the volume of a sphere with a radius that is input by you.
Your program will display the result on the screen. Your input to the main()
is a floating point number.
Should define each
routine of your own
4