EditEdit
MasterMaster
texttext
stylesstyles
Practical Lecture 1: Concepts &
Basics of C++ Programming
Quick Recap
Let’s take a quick recap of previous lecture –
A) Procedural Oriented Programming Paradigm
B) Object Oriented Programming Paradigm
C) Structure
D) Union
E) Enumeration
F) Static Members Of Class
Today’s Agenda
Today we are going to cover -
● MCQ Practice Questions
● Theory Practice Question
● Coding Practice Question
● Q&A Time
MCQ Questions
Let’s Get Started-
Problem - 1
Ques 1. Which of the following statement is incorrect about “cin”?
A. “cin” statement is the instance of the class istream
B. It is used to display output on the screen.
C. The extraction operator << is used along with the object cin for reading inputs.
D. Option 2 and 3 are in correct.
Solution
Ques 1. Which of the following statement is incorrect about “cin”?
A. “cin” statement is the instance of the class istream
B. It is used to display output on the screen.
C. The extraction operator << is used along with the object cin for reading inputs.
D. Option 2 and 3 in correct.
Problem - 2
2. Which of the following is a valid class declaration?
A. Class A { int x; };
B. Class B { }
C. Public class A { }
D. Object A { int x; };
Solution
2. Which of the following is a valid class declaration?
A. Class A { int x; };
B. Class B { }
C. Public class A { }
D. Object A { int x; };
Explanation: Class A { int x; }; is a valid class declaration.
Problem - 3
3. Which of the following keywords is used to control access to a class member?
A. Default
B. Break
C. Protected
D. Asm
Solution
3. Which of the following keywords is used to control access to a class member?
A. Default
B. Break
C. Protected
D. Asm
Ans : C
Explanation: Protected keywords is used to control access to a class member
Problem - 4
4.What is the size of empty class?
A. 0
B. 2
C. 4
D. 1
Solution
4.What is the size of empty class?
A. 0
B. 2
C. 4
D. 1
Explanation: When we create object of empty class at that time State of that object
is nothing. Behaviour of that object is also nothing, but compiler assigns a unique address to that
object. Memory in Computer is always organized in the form of bytes and minimum memory available
at object address location is 1 byte. That's why size of object of empty class is 1 byte
Problem - 5
5. The data elements in the structure are also known as what?
A.) objects
B.) members
C.) data
D.) objects & data
Solution
5. The data elements in the structure are also known as what?
A.) objects
B.) members
C.) data
D) objects & data
Explanation: Variables declared inside a class are called as data elements or data members.
Problem - 6
6. 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
Solution
6. 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
Explanation: While the structure is declared, it will not be initialized, So it will not allocate
any memory
Problem-7
7. Which of the following is a properly defined structure?
A.) struct {int a;}
B.) struct a_struct {int a;}
C.) struct a_struct int a;
D.) struct a_struct {int a;};
Solution
7. Which of the following is a properly defined structure?
A.) struct {int a;}
B.) struct a_struct {int a;}
C.) struct a_struct int a;
D.) struct a_struct {int a;};
Explanation: option struct {int a;} is not correct because name of structure and ;(after declaration)
are missing. In option struct a_struct {int a;} ; is missing. In option struct a_struct int a; {} are missing.
Problem-8
8. Which keyword should be used to declare static variables?
A.) static
B.) stat
C.) common
D.) const
Solution
8. Which keyword should be used to declare static variables?
A.) static
B.) stat
C.) common
D.) const
Answer: a
Explanation: The keyword used to declare static variables is static. This is must be used while
declaring the static variables. The compiler can make variables static if and only if they are mentioned
with static keyword.
Problem-9
9.The static data member ______________________
A.) Must be defined inside the class.
B.) Must be defined outside the class.
C.) Must be defined in main function.
D.) Must be defined using constructor.
Solution
9.The static data member ______________________
A.) Must be defined inside the class.
B.) Must be defined outside the class.
C.) Must be defined in main function.
D.) Must be defined using constructor.
Answer: b
Explanation: The static data members must be defined outside the class. Since these are
common to all the objects and should be created only once, they must not be defined in the
constructor
Problem-10
10.If object of class are created, then the static data members can be accessed
____________
A.) Using dot operator
B.) Using arrow operator
C.) Using colon
D.) Using dot or arrow operator
Soultion
10.If object of class are created, then the static data members can be accessed
____________
A.) Using dot operator
B.) Using arrow operator
C.) Using colon
D.) Using dot or arrow operator
Explanation: The static data members can be accessed in usual way as other members are
accessed using the objects. The dot operator is used generally. Arrow can be used with the
pointers.
Let’s have a quick hands-on some practice Questions
1.Explain Procedural paradigms with example.
2.What do you understand by input and output stream.
3.What do you understand by class explain with example.
4.What is difference b/w class and object?
5.How can we access private data members?
6.How can we access protected data members?
7.What is structure explain with example.
8.What Union are important explain with example.
9.Explain Enumeration with example.
10.What is static members and static members functions.
Coding Questions Time
1. Write a program in C++ to convert temperature in Celsius to Fahrenheit.
Sample Output:
Convert temperature in Celsius to Fahrenheit :
Input the temperature in Celsius : 35
The temperature in Celsius : 35
The temperature in Fahrenheit : 95
Coding Questions Time
2.Write a program to print all the prime number from 1-100.
3.Write a program to print the factorial of a number.
Input:-5
Output:-120
4.Write a C++ program to find LCM of two numbers using functions.
Coding Questions Time
5. Define a class TEST in C++ with following description:
• Private Members
• TestCode of type integer
• Description of type string
• NoCandidate of type integer
• CenterReqd (number of centers required) of type integer
• A member function CALCNTR() to calculate and return the number of centers as
• (NoCandidates/100+1)
• Public Members
- A function SCHEDULE() to allow user to enter values for TestCode, Description, NoCandidate & call function CALCNTR()
to calculate the number of Centres
- A function DISPTEST() to allow user to view the content of all the data members
Coding Questions Time
6. An array stores details of 25 students (roll no, name, marks in three subject).
Write a program to create such an array and print out a list of students who have failed in
more than one subject.
QNA Time
Any Questions ??
Any Questions??
Thank You!
See you guys in next class.