Sunteți pe pagina 1din 4

After Mid-Term:

1. Put (F) for the false statement and correct it, otherwise put (T) :

1) Structure is a user defined data type which allows you to combine data items of different kinds.
2) A function declaration tells the compiler about a function's name and return type only.
3) The array, which stores a fixed-size sequential collection of elements of the different type.
4) A class definition must be followed either by a semicolon or a list of declarations.
5) You can overload function declarations that differ only by return type.
6) When you define a class, you define a blueprint for a data type. This is actually reserve space in
memory.
7) The data and function that operate on data are bundled as a unit called as object.
8) The parameters listed in the function declaration are considered global variables .
9) The following is legal in a void function (return x;) .

2. Write a program that prompts the user to enter ten students data (id - name - address - 3 subjects
mark) and print it after filling the data (using structure).

3. Write a C++ program to prompt the user to fill an array of 10 elements of students scores and print
it after sorting the array. Print also the average, greatest and the minimum score.

4. Write a C++ function that return true if passing to it an even number and false otherwise.
5. Design a class named Point to represent a Point. The class contains:

Two double data fields named X and Y that specify the point coordinates and string data field
named color that specify point color.
A method named move() that change the point position (not allowed to be negative values).
A method setColor() that set the point color.
A method getx() that return the value of X.
A method gety() that return the value of Y.
A method print() that print the point coordinates and its color.

6. Design a class named Square to represent a Square. The class contains:

A double data field named Side specifies a square side.


A method named move() that change the point position (not allowed to be negative values.
A method setSide() that set aside (not allowed to be negative values).
A method getSide() that return the value of Side.
A method getArea() that return the area of a square (Area of square = Side*Side).
A method getPerimeter() that return the perimeter of a square (Perimeter of square = 4*Side).

7. Choose the correct answer:

1) Which of the following is a legal call to the displayOutput function?


a. void displayOutput(int total);
b. void displayOutput(myTotal);
c. displayOutput(int mytotal);
d. displayOutput(myTotal);
e. cout << displayOutput(myTotal);

2) If you have a class named myPersonClass, which of the following correctly declare a
constructor in the class definition?
a. myPersonClass::myPersonClass();
b. myPersonClass();
c. init();
d. cast();

3) What is wrong with the following code?


float scores[10], total;
a. Cannot declare regular and array variables together.
b. Arrays must be integers
c. The 10 should be replaced with a variable name, whose value is input from the user
d. Nothing.
4) Given an array named scores with 25 elements, what is the correct way to access the 25th
element?
a. scores+25
b. scores[24]
c. scores[25]
d. scores[last]

5) Which of the following will correctly assign all the values in one array to the other array?
(Assume both arrays are of the same type and have SIZE elements)
a. array1=array2;
b. array1[]=array2;
c. for(i=0; i<SIZE ;i++)
array1[i]=array2[i];
d. for(i=0; i<SIZE ;i++)
array1[]=array2[];

6) Which of the following will read values from the keyboard into the array? (Assume the size of
the array is SIZE).
a. cin >> array;
b. cin >> array[];
c. cin >> array[SIZE];
d. for(i=0; i<SIZE; i++)
cin >> array[i];

7) What is the value of choice after the following statements?


void getChoice (int& x, int y);
void main ( )
{
int choice, count=3;
getChoice (choice, count);
}
void getChoice(int& x, int y)
{
if (y<0)
x = 0;
if (y == 0)
x = -1;
else
x = 99;
return;
}
a. 3
b. 0
c. 1
d. 99
8) When defining a class, the class should be composed of the kind of values a variable of the
class can contain, and
a. member functions for that class
b. the keyword private
c. other class definitions
d. nothing else

9) Given the following structure definitions, what is the correct way to print the person's birth
year?

struct DateType
{
int day;
int month;
int year;
}
struct PersonType
{
int age;
float weight;
DateType birthday;
}
PersonType person;
a. cout << person.birthday.year;
b. cout << year;
c. cout << birthday.year;
d. cout << peson.year;

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