|
FINALTERM EXAMINATION
SPRING 2006
CS201 - INTRODUCTION TO PROGRAMMING (Session - 3 )
Marks: 50
Time: 120min
StudentID/LoginID: ______________________________
Student Name: ______________________________
Center Name/Code: ______________________________
Exam Date: Wednesday, August 23, 2006
Please read the following instructions carefully before attempting any of the questions:
1. Attempt all questions. Marks are written adjacent to each question.
2. Do not ask any questions about the contents of this examination from anyone.
a. If you think that there is something wrong with any of the questions, attempt it to the best of your understanding.
b. If you believe that some essential piece of information is missing, make an appropriate assumption and use it to solve the problem.
c. Write all steps, missing steps may lead to deduction of marks.
d. All coding questions should be answered using the C ++ syntax.
You are allowed to use the Dev-C++ compiler to write and test your code. If you do so please remember to copy and paste your code into the examination solution area. (Do NOT share your code; your colleague could get higher marks than you!!)
**WARNING: Please note that Virtual University takes serious note of unfair means. Anyone found involved in cheating will get an `F` grade in this course.
For Teacher's use only
Question 1 2 3 4 5 6 7 8 9 Total
Marks
Question No: 1 ( Marks: 2 ) - Please choose one
To access the 8th element of an int array named myArray of 15 elements, you would write
►
int[8]
►
int[7]
►
myArray[8]
►
myArray[7]
Question No: 2 ( Marks: 2 ) - Please choose one
A friend function of a class has access
►
To all data member and functions of the class
►
Only to other friend functions of the class
►
Only to private data of the class
►
Only to public data of the class
Question No: 3 ( Marks: 2 ) - Please choose one
A copy constructor is always called when
►
an object is initialized with another object data of the same class when it’s created
►
an object is initialized with another object of any class when it’s created
►
an object is initialized with a variable of a basic type when it’s created
►
an object is not initialized when it’s created
Question No: 4 ( Marks: 2 ) - Please choose one
Consider the function below:
template
T abc (U x)
{
return (-x);
}
We call this function as
cout << abc(-9.6) << endl;
The answer will be:
►
9.6
►
-9.6
►
9
►
-9
Question No: 5 ( Marks: 6 )
Calculate the following bitwise operations.
a) 01001000 & 10111000 =
b) 01001000 | 10111000 =
c) 01110010 ^ 10101010 =
Question No: 6 ( Marks: 10 )
Write a program that will create a class stat. the class stat has the following data members.
A float array values of size 10.
The variables sum and avg both of type float.
The class stat has the following member functions.
takedata()
calculate()
show()
The function takedata() is used to read data from the user through keyboard into the array values. The function calculate() is used to calculate the sum of all values in the array values and store the value in the variable sum. The function calculate(), then calculates the average by using the formula sum/10 and stores the result in the variable avg. The function show() is used to display the value in avg on the screen.
The program will create an object obj1 in the class stat. The program will read data into obj1 using takedata(), calculate the average using the function calculate() and then display the result using show() function.
Question No: 7 ( Marks: 10 )
Write a program that will create a class rectangle. The class rectangle has the data members width and height, both of type float. The class rectangle has one member function getdata(). The program will create two objects rect1 and rect2 of the class rectangle. The program will read data into rect1 and rect2 trough the function getdata(). The program will compare both the objects by overloading “==” operator to decide that rect1 and rect2 are same or not.
If rect1 and rect2 are same then program will display the message “Both rectangles are same” otherwise the program will display “Both rectangles are not same”.
Note: rectangles are called same if their heights and widths are same.
Question No: 8 ( Marks: 8 )
Write a program that will calculate the volume of a sphere using function templates.
The function name is volumecal(). Two arguments (i.e. radius and a constant pi) are passed to the function volumecal(). After calculating the volume the, the function volumecal() display the result on the screen.
The formula for volume of sphere is
volume= (4/3) * pi * (radius)3
Where pi= π=3.141569
Question No: 9 ( Marks: 8 )
We have two classes Class1 and Class2 and we want to construct two way friendships between them. Write the coding sketch to achieve this friendship.
http://ping.fm/EJnTo
SPRING 2006
CS201 - INTRODUCTION TO PROGRAMMING (Session - 3 )
Marks: 50
Time: 120min
StudentID/LoginID: ______________________________
Student Name: ______________________________
Center Name/Code: ______________________________
Exam Date: Wednesday, August 23, 2006
Please read the following instructions carefully before attempting any of the questions:
1. Attempt all questions. Marks are written adjacent to each question.
2. Do not ask any questions about the contents of this examination from anyone.
a. If you think that there is something wrong with any of the questions, attempt it to the best of your understanding.
b. If you believe that some essential piece of information is missing, make an appropriate assumption and use it to solve the problem.
c. Write all steps, missing steps may lead to deduction of marks.
d. All coding questions should be answered using the C ++ syntax.
You are allowed to use the Dev-C++ compiler to write and test your code. If you do so please remember to copy and paste your code into the examination solution area. (Do NOT share your code; your colleague could get higher marks than you!!)
**WARNING: Please note that Virtual University takes serious note of unfair means. Anyone found involved in cheating will get an `F` grade in this course.
For Teacher's use only
Question 1 2 3 4 5 6 7 8 9 Total
Marks
Question No: 1 ( Marks: 2 ) - Please choose one
To access the 8th element of an int array named myArray of 15 elements, you would write
►
int[8]
►
int[7]
►
myArray[8]
►
myArray[7]
Question No: 2 ( Marks: 2 ) - Please choose one
A friend function of a class has access
►
To all data member and functions of the class
►
Only to other friend functions of the class
►
Only to private data of the class
►
Only to public data of the class
Question No: 3 ( Marks: 2 ) - Please choose one
A copy constructor is always called when
►
an object is initialized with another object data of the same class when it’s created
►
an object is initialized with another object of any class when it’s created
►
an object is initialized with a variable of a basic type when it’s created
►
an object is not initialized when it’s created
Question No: 4 ( Marks: 2 ) - Please choose one
Consider the function below:
template
T abc (U x)
{
return (-x);
}
We call this function as
cout << abc(-9.6) << endl;
The answer will be:
►
9.6
►
-9.6
►
9
►
-9
Question No: 5 ( Marks: 6 )
Calculate the following bitwise operations.
a) 01001000 & 10111000 =
b) 01001000 | 10111000 =
c) 01110010 ^ 10101010 =
Question No: 6 ( Marks: 10 )
Write a program that will create a class stat. the class stat has the following data members.
A float array values of size 10.
The variables sum and avg both of type float.
The class stat has the following member functions.
takedata()
calculate()
show()
The function takedata() is used to read data from the user through keyboard into the array values. The function calculate() is used to calculate the sum of all values in the array values and store the value in the variable sum. The function calculate(), then calculates the average by using the formula sum/10 and stores the result in the variable avg. The function show() is used to display the value in avg on the screen.
The program will create an object obj1 in the class stat. The program will read data into obj1 using takedata(), calculate the average using the function calculate() and then display the result using show() function.
Question No: 7 ( Marks: 10 )
Write a program that will create a class rectangle. The class rectangle has the data members width and height, both of type float. The class rectangle has one member function getdata(). The program will create two objects rect1 and rect2 of the class rectangle. The program will read data into rect1 and rect2 trough the function getdata(). The program will compare both the objects by overloading “==” operator to decide that rect1 and rect2 are same or not.
If rect1 and rect2 are same then program will display the message “Both rectangles are same” otherwise the program will display “Both rectangles are not same”.
Note: rectangles are called same if their heights and widths are same.
Question No: 8 ( Marks: 8 )
Write a program that will calculate the volume of a sphere using function templates.
The function name is volumecal(). Two arguments (i.e. radius and a constant pi) are passed to the function volumecal(). After calculating the volume the, the function volumecal() display the result on the screen.
The formula for volume of sphere is
volume= (4/3) * pi * (radius)3
Where pi= π=3.141569
Question No: 9 ( Marks: 8 )
We have two classes Class1 and Class2 and we want to construct two way friendships between them. Write the coding sketch to achieve this friendship.
http://ping.fm/EJnTo