Week 2 Assignment OOP C++
Week 2 Assignment OOP C++
Roll no
Name
2. Which of the following is the correct syntax of including a user defined header files in C+
+?
a) #include <userdefined.h>
b) #include <userdefined>
c) #include “userdefined”
d) #include [userdefined]
a) yes
b) no
c) do nothing
d) yes and no
int x = 0;
for(x = 5; x < 8; ++x);
cout << x << " ";
cout << endl;
a) 5 6 7
b) 6 7
c) 5
d) 8
9. How many times does the cout statement in the following code execute?
int a = 2;
int b = 6;
while(a < 10)
for(int b = 0; b < 4; ++b)
{
cout << a << " " << b << " ";
++a;
}
cout << endl;
a) 8
b) 12
c) 10
d) indefinitely
10. What is the index number of the last element of an array with 9 elements?
a) 9
b) 8
c) 0
d) Programmer-defined
13. If you declare an integer pointer as int* pt; and you declare an integer variable as
int num; , then which of the following is legal?
a) num = &pt;
b) pt = #
c) *num = *pt;
d) &num = pt;
14. Values that are used to end loops are referred to as ------------- values.
a) closing
b) ending
c) sentinel
d) stop
a) Null
b) Zero
c) Address of an object of same type
d) All of them
a) Direct calling
b) Indirection
c) Pointer referencing
d) All of the above
18. What is the scope of the variable declared in the user defined function?
a) Whole program
b) Only inside the {} block
c) The main function
d) None of the above
19. How many minimum numbers of functions need to be presented in c++?
a) 0
b) 1
c) 2
d) 3
20. Which of the following gives the memory address of the first element in array?
a) array[0];
b) array[1];
c) array(2);
d) array;
21. What is the output of this program?
#include <stdio.h>
using namespace std;
int main()
{
char str[5] = "ABC";
cout << str[3];
cout << str;
return 0;
}
a) ABC
b) ABCD
c) AB
d) None of the mentioned
22. Which of the following gives the [value] stored at the address pointed to by the pointer :
ptr?
a) Value(ptr)
b) ptr
c) &ptr
d) *ptr
23. What will happen when the structure is declared?
a) it will not allocate any memory
b) it will allocate the memory
c) it will be declared and initialized
d) it will be declared
24. What will be the utput of the following c++ code?
#include <iostream>
#include <string.h>
int main()
struct student
int num;
char name[25];
};
student stu;
stu.num = 123;
strcpy(stu.name, "sukant");
return 0;
}
a) 123
sukant
b) sukant
sukant
c) Compile time error
d) runtime error
Write C++ programs for the following questions given. Your answer should also include
output of programs.
1. Write a program that reads a Celsius degree in a double value from the console, then
converts it to Fahrenheit and displays the result. The formula for the conversion is as
follows:
fahrenheit = (9 / 5) * celsius + 32
Sample Output:
=====================================
Italian Woods Furniture Company
=====================================
Enter P for pine, O for oak or M for mahogany : M
How many tables do you want : 3
3. Create a structure named Apartment that contains data fields to hold the number of
bedrooms, the number of baths, and the monthly rent for the Apartment. Write a program
that creates an Apartment object and prompts the user for number of bedrooms and baths
desired. Determine the rent from the following table and set the rent field appropriately.
If a requested apartment type is not available, set the rent field to 0.
Display all the data including an error message if the entered data is invalid, or if no
apartments are available with the requested combination. [20 marks]