Вы находитесь на странице: 1из 1

AIR UNIVERSITY

Faculty of Computing & Artificial Intelligence |Department of Computer Science Fall 2019

Course: CS102 –Programming Fundamentals | Batch: BSCYS-1B | (47)

THEORY Assignment # 03
Submission Deadline: SAT, 7th Dec, 2019 at 11:59 pm | Total Marks: 40
Directions: Please upload the solutions in PDF format on Google Classroom Only, through your accounts.
Policy: Any assignment copied will be marked zero and the assignments discarded. Both the original and
copied assignments will be treated equally.

Problem Statements:
1. Write a function that displays at the left margin of the screen a solid square of asterisks whose side is
specified in integer parameter side by the user. For example, if side is 4, the function displays the
following:
****
****
****
**** (10 Marks)

2. Write a function that, when you call it, displays a message telling how many times it has been called:
“I have been called 3 times”, for instance. Write a main() program that calls this function
at least 10 times. Try implementing this function in two different ways.
a) First, use a global variable to store the count.
b) Second, use a local static variable. (5 + 5 = 10 Marks)
3. Write a program that determines which of 5 geographic regions within a major city (north, south, east,
west, and central) had the fewest reported traffic accidents last year. It should have the following two
functions, which are called by main.
a) int getNumAccidents() is passed the name of a region. It asks the user for the number
of traffic accidents reported in that region during the last year, validates the input, then returns
it. It should be called once for each city region.
b) void findLowest() is passed the five accident totals. It determines which is the smallest
and prints the name of the region, along with its accident figure.
Input Validation: Do not accept an accident number that is less than 0. (10 Marks)

4. Write a program that computes and displays the charges for a patient’s hospital stay. First, the program
should ask if the patient was admitted as an in-patient or an out-patient.
If the patient was an in-patient the following data should be entered by user:
• The number of days spent in the hospital
• The daily rate
• Charges for hospital services (lab tests, etc.)
• Hospital medication charges.
If the patient was an out-patient the following data should be entered by user:
• Charges for hospital services (lab tests, etc.)
• Hospital medication charges.
The program should use two overloaded functions to calculate the total charges. One of the functions
should accept arguments for the in-patient data, while the other function accepts arguments for out-
patient data. Both functions should return the total charges.
Input Validation: Do not accept negative numbers for any information.
(10 Marks)

Page 1 of 1

Вам также может понравиться