Lab 07

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

CONFIDENTIAL

COMPUTER SCIENCE PROGRAM


FACULTY OF COMPUTING AND INFORMATICS
UNIVERSITI MALAYSIA SABAH

KT14303 PROGRAMMING PRINCIPLES


Lab 07 Pointers
______________________________________________________________________________

Student Matric No :
Student Name:
Program: HC00/ HC05 / HC14

Learning Objectives/Outcomes:
Upon completion of this lab, the student should be able to:
i. define, initialize and use pointer
ii. work with a common algorithm for processing the value of pointers
iii. write a function that receives andreturnsn pointers
iv. apply the concepts of pointers in solving the complex programming problems

INSTRUCTION: ANSWER ALL QUESTIONS

Practice 1: Working with SmartV3 system (Estimate 15 minutes to 30 minutes)


Write a program that read two numbers from user and then sorting these two numbers in
ascending order that is from the smallest to largest. Write sortAscendOrder function to sorting
them in the ascending order, which num1 is the smallest number.

void sortAscendOrder (double*, double *)

SAMPLE RUN:
ASCENDING ORDER PROGRAM
Enter three numbers separated by single blanks => 7.5 9.6 5.5
The number in ascending order is : 5.50 7.50 9.60

Practice 2: (Estimate 15 minutes to 30 minutes)


Write a program for an automatic teller machine that dispenses money. The user should enter
the amount desired ( a multiple of 10 dollars) and the machine dispenses this amount using the
least number of bills. The bills dispensed are 100s, 50s, 20s, and 10s. Write a function that
determine how many of each kind of bill to dispense.

void instruct(void);
void dispenser (int amount, int *th, int *ft, int *tw, int *tn);

Copyright © Universiti Malaysia Sabah


CONFIDENTIAL

Sample Run :
ABC BANK Automatic Teller Machine ATM
Enter withdraw Amount: 1
Invalid Input!
Please enter a multiple of 10 dollars

Enter withdraw Amount: 5


Invalid Input!
Please enter a multiple of 10 dollars

Enter withdraw Amount: 100


Number of 100 bills: 1
Number of 50 bills: 0
Number of 20 bills: 0
Number of 10 bills: 0

Practice 3: (Estimate 30 minutes to 60 minutes) -10%


A hospital supply company wants to market a program to assist with the calculation of
intravenous rate. Design and implement a program that interacts with the user as follows.

Sample Run:
INTRAVENOUS RATE ASSISTANT

Enter the number of the problem you wish to solve.


GIVEN A MEDICAL ORDER IN CALCULATION RATE IN
(1)ml/hr & tubing drop factor drops/min
(2)1 L for n hr ml/hr
(3) mg/kg/hr & concentration in mg/ml ml/hr
(4) units/hr & concentration in units/ml ml/hr
(5) QUIT

Problem=>1
Enter the rate in ml/hr => 150
Enter tubing’s drop factor (drops/ml) => 15
The drop rate per minute is 38.

For more example of sample run, kindly refer to textbook, question 2 page 353.
Your program should include the following functions :
• get_problem : Display the user menu, then inputs and returns as the function value
the problem number selected.
• get_rate_drop_factor : Prompts the user to enter the data required for problem 1,
and send this data back to the calling module via output parameters.
• get_kg_rate_conc-prompts the user to enter the data required for problem 3, and
sends this data back to calling module via output parameters.

Copyright © Universiti Malaysia Sabah


CONFIDENTIAL

• get_unit_conc- prompts the user to enter the data required for problem 4 and sends
this data back to calling module via output parameters.
• fig_drops_min - takes rate and drop factor as input parameters and returns
drops/min (rounded to nearest whole drop) as function value
• fig_ml_hr – takes as input parameter the number of hours over which one liter is to be
divired and returns ml/hr (rounded) as function value.
• by_weight – Takes as input parameters rate in mg/kg/hr, patient weight in kg, and
concentration of drug in mg/ml and returns ml/hr (rounded) as function value.
• by_units – Takes as input parameters rate in units/hr and concentration in units/ml,
and returns ml/hr(rounded) as function value.
[ Hint : Use a sentinel-controlled loop. Call get_problem once before the loop to
initialize the problem number and once again at the end of the loop body to update it ].

Marking Rubrics:
Assessment Rubric:
Criteria Advanced Proficient Functional Developing
(10-9) (8-7) (6-4) (0-3)
Applicability of Shows excellent Shows a good Shows minimal Show no
Concepts in understanding of understanding of understanding of understanding of
solving given the theory taught the theory taught the theory taught the theory taught
problems and is able to and is able to and is able to and is able to
(5%) integrate the integrate the integrate the integrate the
concepts in solving concepts in solving concepts in solving concepts in solving
the given problems the given problems the given problems the given problems

Deliverables The deliverables The deliverables Minor flaws in Major flaws in


(5%) are precise as are appropriate, as deliverables as deliverables as
demonstrated demonstrated demonstrated demonstrated
sample run. sample run. sample run. sample run.

Program executes Program executes Program executes Program does not


correctly with no somewhat incorrectly with execute (consists
syntax or runtime correctly with <= 3 logic or runtime of syntax errors)
errors. logic and runtime errors >= 3 logic
errors. errors.

Highly efficient in Efficient in Somewhat efficient Inefficient in


managing process managing process in managing managing process
memory and CPU memory and CPU process memory memory and CPU
usage. usage and CPU usage usage

Copyright © Universiti Malaysia Sabah


CONFIDENTIAL

Plagiarism <30% Similarity 30-40% Similarity 40-50% Similarity >50% Similarity


Penalty
(deduction from
overall scoring)

Delivery The program was The program was The code was The code was
(Deduction from delivered on time delivered within a within 2 more
overall scoring) week weeks of the due than 2 weeks
of the due date. date overdue.

*************************** THE END ******************************

Copyright © Universiti Malaysia Sabah

You might also like