2/08/2011

BCT1113 Test 1 (sample)-SOLUTION

1. Respond with the correct answer by marking either True "T" or False "F" for each question.

a) High-level languages include Basic, FORTRAN, COBOL, Pascal, C, C++, C#, and Java (T)

b) Compiler: translates a program written in a high-level language into machine language (T)

c) Preprocessor directives begin with # and are processed by a the preprocessor (T)

d) Use the compiler to: Check that the program obeys the rules (T)

e) Linker: Combines object program with other programs provided by the SDK to create executable code (T)

f) Programming is a process of problem solving (T)

g) Algorithm: Step-by-step problem-solving process (T)

h) Two popular approaches to programming design: - 1) Structured 2) Object-oriented (T)

i) The structured design approach is also called Modular Design (T)


 

2. Print the output of the following C++ statement. If nothing prints, then answer "nothing". Assume x=3 and y=2.

Example) cout<<x;            3


 

a) cout<<y;            2

b) / * cout<<y; */        nothing

c) // cout<<x+y;        nothing

d) cout<<x<<y;        32

e) cout<<x<<endl<<y;

3

2

f) cout<<x+y;            5

g) cout<<"x+y="<<x+y;    x+y=5

h) cin>>x%y;            1

i) cout<<++x;            4

j) cout<<y++;            2


 

3. Print the output of the following C++ statement. If nothing prints, then answer "nothing".


 

a)     if(1<3)

cout<<"Yes";

else

cout<<"No";

yes

b)     char race='M';

if ((race=='m') ||( race =='M')) then

cout<<"Malay";

else

cout<<"Others";

    Malay

c)      char race='M';

     int age = 21;

if ((race=='m') &&( age <=20)) then

cout<<"MARA LOAN";

else

cout<<"PTPTN LOAN";

    PTPTN LOAN

4. What is the output of the following C++ code segment:-


 

char race;

     int age;

    cin>>race>>age;

if(race='m')

        if(age<=20)

            cout<<"MARA LOAN";

        else

            cout<<"PTPTN LOAN";

else

cout<<"OTHER LOAN";


 

  1. When the user inputs "C" for race and 21 for age

    OTHER LOAN


     

b) When the user inputs "C" for race and 18 for age

OTHER LOAN

  1. When the user inputs "m" for race and 21 for age

    PTPTN


     

d) When the user inputs "m" for race and 18 for age

MARA LOAN


 

5. Prepare an algorithm (pseudo code or flowchart) and write a C++ program for each of the following problem.


 

a) Write a program to find perimeter and area of a rectangle. The perimeter and area of the rectangle are given by the following formulas:

perimeter = 2 * (length + width)

area = length * width


 

b) Write a program to read user id and password .if the password is "abubakar" and password is 6855 then print out "Your password is accepted". Otherwise print "Not Accepted".

No comments:

Cara download Installer windows 10 dalam format ISO

1. Jika anda bercadang untuk download windows 10 melalui website rasmi windows - pilihan untuk download dalam format ISO tidak di berikan.  ...