Sunteți pe pagina 1din 6

CSC2203(F) Page 1 of 6

INTI INTERNATIONAL UNIVERSITY

B.Eng (HONS) IN CIVIL ENGINEERING (BCEGI)

CSC2203: INTRODUCTION TO PROGRAMMING


FINAL EXAMINATION: JUNE 2015 SESSION

This paper consists of SIX (6) questions. Answer any FOUR (4) questions in the answer booklet
provided. All questions carry equal marks.

Question 1

Develop a C Program for the following scenario. Cashier will enter the product and the quantity
which purchased by the customer. The program will display product name, the price of the
product and total payment that need to pay by the customer.

Product (Code) Price per kg (RM)


1 68.00
2 58.00
3 78.00

Sample Output:

(25 marks)
CSC2203(F) Page 2 of 6

Question 2

a) The function below uses selection sort algorithm to sort a set of 10 integer data that are
stored in an array. Complete the function.

void sort( int list[10])

int i,j,temp;

for(i = 0; i < 9; ++i)

for( j = ___<1>_____ ; ____<2>______ ; ++j)

if ( _______<3>___________ )

______<4>_________ ;

_________<5>_______ ;

________<6>__________ ;

}
(13 marks)
b) Trace the following program and produce the output.

#include <stdio.h>
main()
{
int x = 10, y = 20;
int z;
z = ++x + y--;
printf(\nx = %d y = %d z = %d,x,y,z);
++x;
z = x++ + y--;
printf(\nx = %d y = %d z = %d,x,y,z);
}
(12 marks)
CSC2203(F) Page 3 of 6

Question 3

a) Write single C statement for the following instruction.

a. Declare an array called messageOne which holds a string value C


b. Programming.
c. Declare another array of characters call messageTwo.
d. Copy the content of messageOne to messageTwo.
(5 marks)
b) The following program calculates and displays the sum, the multiplication and the
average of the 3 numbers. The program contains 3 functions. Function getSum()
receives the 3 integer values and returns the total of these 3 values. Function
getMul() receives the 3 integer values and returns the multiplication of the 3
values. Function getAverage() receives the total and returns the average of the 3
values. The program contains many syntax and logic errors. Correct the program
and rewrite the program.

#include <stdio.h>
void getSum(int);
void getMul(int);
float getAverage();

void main ()
{
int number1, int number2 , int number3, sum,avg,mul;

printf(Enter 3 integer numbers : );


scanf(%d %d %d,number1,number2,number3);
sum = getSum();
avg = getAverage();
mul = getMul();
printf(Sum = %d Average = %d Multiplication = %d);
}
void getSum(int x,y,z) {
return (x+y+z);
}
void getMul(int x, y,z) {
return (x*y*z);
}
void getAverage(){
return sum/3.0;
}
(20 marks)
CSC2203(F) Page 4 of 6

(20 marks)
Question 4

A form contains the following information:

Student Name
Stuednt Id number
Faculty
Semester

Answer the following questions based on the information contained in the above form.

a) Declare a structure call PlayerInfo containing the above members.


(5 marks)

b) Declare an array of 20 structures PlayerInfo variable called IFC.


(3 marks)

c) Write a function to enter values for the array of structures declared in (b).
(6 marks)

d) Write a function that will display the players name who are from the FOSTEM
faculty.
(11 marks)
.

Question 5

a) Write a function that will receive an array of 10 integer values and one integer type of
data that represents the data to search. The function will return the location where the
integer data was found in the array. If the data is not in the array, the function will
return a -1.
(8 marks)
CSC2203(F) Page 5 of 6

b) Trace the following programs and produce the output.

i)

#include <stdio.h>
main()
{

int x = 28, y = 5;

while( x > y)
{
printf("\nx = %d",x);
x-= 5;
while ( x > 15)
--x;
printf("\nx = %d",x);

}
(12 marks)

ii)
#include<stdio.h>
void swap(int , &int);
main()
{
int x = 10, y = 28;
swap(x,y);
printf(\nx = %d y = %d,x,y);
}

void swap(int x, int& y)


{
int temp = x;
x = y;
y = temp;
printf(\nx = %d y = %d,x,y);
}
(5 marks)
CSC2203(F) Page 6 of 6

Question 6

a) Write a program that will convert a celsius to fahrenheit. The program should have a
function that will receive the celsius value and returns the equivalent Fahrenheit
value.

Formula : Fahrenheit = (9/5) * Celsius + 32


(11 marks)

b) Rewrite the following program using a switch case statement.

If ( code == A ||m code == a)


callfunctionA();
else if ( code == B || code == b)
callfunctionB();
else if ( code == C || code == c)
callfunctionC();
else printf(invalid code);

(8 marks)

c) Using the conditional operator (? :), write a program that will determine if a number
entered by the user is a positive number or a negative number.
(6 marks)

S-ar putea să vă placă și