Uploaded by Devub Das

null (9)

advertisement
IT1010 Introduction to Programming
Mid Semester Examination (20 marks)
How to do this Assignment: (Read All Instructions carefully)
1. Select one real world problem or operation that can be solved using your knowledge
gained in the introduction to programming module. The problem should have
a. Repetition
b. Selection – with minimum of 3 choices
c. Calculation
Describe the problem using your own words.
2. Write a solution for the above problem using C.
3. Write test cases (minimum of two) for your program covering all possible situations
that can happen.
4. Show your program output for the above test cases.
5. You should not copy from others. All assignments will be uploaded to Turnitin
plagiarism detection tool. Similarity score greater than 30% will bring you 0 marks.
6. Please refrain from copying from internet or from books either, since there is a danger
that two students copy from same source, and will end up with 0 marks.
7. You have to prepare one word document file (your_studnet_id.docx) with answers
for all the sections from 1 - 4.
8. Submit the word document file (your_studnet_id.docx) and pdf version of the same
document (your_studnet_id.pdf) as zip folder to the relevant course web link.
9. Submission deadline is 9th of April 2020, on or before 5.00 p.m.
Sample answer
ABC higher education institute offers three courses in this academic year. The courses and
their registration fees are given in the following table.
Course Type
H
M
F
Course Name
Diploma in Hospitality Management
Diploma in Marketing
Diploma in Finance
Registration Fee (Rs.)
1500.00
2000.00
2500.00
Only 10 students will be registered for all three courses within one academic year. The
registration for all three courses will be held on the same day first come first serve basis.
Write a C program to register students for the above courses by entering their course type
from the keyboard. The program should accept both uppercase and lowercase letters as
correct inputs for course type. Your program should display the number of students
registered for each course and the total registration fee earned from each course. When the
course type is invalid, the program should display an error message.
The program should terminate the registration when the total number of registrations
becomes 10 or there are no more registration to be done.
#include <stdio.h>
int main(void)
{
char type, ch = 'Y';
int sCount = 0, countH = 0, countM = 0, countF = 0;
while ((sCount <= 100) && (ch == 'Y'))
{
printf("\nEnter course type : ");
scanf(" %c", &type);
if(type == 'h' || type == 'H')
countH++;
else if(type == 'm' || type == 'M')
countM++;
else if(type == 'f' || type == 'F')
countF++;
else
printf("Invalid course type");
sCount++;
if (sCount >= 10)
{
printf("\nYou
have
reach
the
maximum
number
of
registrations for the day");
break;
}
else
{
printf("\nDo you want do another registration (Y/N)");
scanf("%*c%c", &ch);
}
}
printf("\n----------------------------------------------");
printf("\n No. students registered for Hospitality
Management: %d\n" , countH);
printf("Registration fee : %.2f\n\n" , countH * 1500.0);
printf("No. students registered for Marketing : %d\n" ,
countM);
printf("Registration fee : %.2f\n\n" , countM * 2000.0);
printf("No. students registered for Finance : %d\n" ,
countF);
printf("Registration fee : %.2f\n" , countF * 2500.0);
return 0;
}
Test Case I : Input less than ten registrations , but finish the registration as the user do not
have more registrations.
Enter course type : H
Do you want do another registration (Y/N): Y
Enter course type : M
Do you want do another registration (Y/N): Y
Enter course type : L
Invalid course type
Do you want do another registration (Y/N): N
Test Case II : Doing maximum number of registration for the day.
Test Case II : Doing maximum number of registration for the year
Enter course type : H
Do you want do another registration (Y/N): Y
Enter course type : M
Do you want do another registration (Y/N): Y
Enter course type : h
Do you want do another registration (Y/N): Y
Enter course type : F
Do you want do another registration (Y/N): Y
Enter course type : F
Do you want do another registration (Y/N): Y
Enter course type : m
Do you want do another registration (Y/N): Y
Enter course type : M
Do you want do another registration (Y/N): Y
Enter course type : f
Do you want do another registration (Y/N): Y
Enter course type : H
Do you want do another registration (Y/N): Y
Enter course type : M
Program output (Screen shot of the program output)
Test case 1
Test case 2
Marking Guide
Part 1
Complexity of the problem
Repetition
3.0 marks
Selection
3.0 marks
Calculation
2.0 marks
Clarity of writing
2.0 marks
Part 2
Correct use of repetition in C
2.0 marks
Correct use of selection in C
1.5 marks
Correct use of calculation in C
1.5 marks
Coding convention
1.0 mark
Part 3
Correct test case
1.0 mark
Part 4
Correct program output
1.0 mark
Part 5
Additional features (display menus , warning messages , nice 2.0 marks
output formats)
Total
20.0 marks
Download