Assessment Type: Formative Assessments: Embedded Questions in Video

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

` <CO3I>: <22316>: <Object Oriented Programming>: < Classes and Objects :> <LO4>:

<Assessments>: <Formative>

<Chetashri Bhusari>

Assessment Type: Formative Assessments: Embedded questions in video

Set 1: Question No 1 Set 1: Question No 2 Set 1: Question No 3

Which symbol is used for scope Which keyword is used to declare Inline function required how many lines
of code in member function declaration?
resolution operator? online keyword?

Recall/ Remembering Recall/ Remembering Recall/ Remembering

a) : a) inline a) one

b) :: b) outside b) two

C) :; c) three

d) .

Ans: b Ans: a Ans: a

Set 2: Question No 1 Set 2: Question No 2

Data members required _____________ Member functions in a class required


which memory whileclass declaration or _____________ which memory while
definition? class declaration or definition?

Recall/ Remembering Recall/

a) same a) same

b) separate b) separate

Ans:b Ans:a
If students have access to laptop/ desktop – they can answer it on LMS, else download it and answer it and file
it for later use. They can also copy the question in their notebook in case the space provided is insufficient.

1. Best suited for subjective questions.


2. Numerical problems
3. Short answer questions

A. List characteristics of member function. B. Give two places where we can declare
member function in a class.

A. Characteristics Of Member Function: B. Member function can be defined in two


places.
● Several different classes can use the
function name. The ‘membership label – 1) Outside the class definition
(class-name :: )’ will resolve their scope.
Inside the class definition
● Member functions can access the private
data of the class. A non member function
cannot do so. However friend function
can access the private data. This is an
exceptional case.

● A member function can call another


member function directly without using
the dot (.) operator.


C. Write down syntax of outside member D. Write a program to declare a class ‘emp’
function declaration syntax. containing data member’s emp_id and
salary. Accept and display this data for 1
object of the class.(Inside member function
declaration)
C. Answer D . Answer
#include<iostream>
Return- data-Type class-name :: function- using namespace std;
name (argument –declaration) class Emp
{
{
private:
function Body int emp_id;
float salary;
} public:
● The membership label ‘class-name:: ‘ void accept()
tells the compiler that the function {
belongs to the spiffed class. cout<<"\n Enter Employee id : ";
cin>>emp_id;
● The symbol “::” is called scope resolution cout<<"\n Enter Salary : ";
operator cin>>salary;
}
void showdata()
{
cout<<"\n Employee id is "<<emp_id;
cout<<"\n Employee salary is :
"<<salary;
}
};
int main()
{
Emp e;
e.accept();
e.showdata();
}
Output:
Output Executed with dev c++

E. EWrite a program to declare a class ‘emp’ F. Write short note on Inline function
containing data member’s emp_id and
salary. Accept and display this data for 1
object of the class.(Outside Member
function declaration)

E Answer Space F. Answer Space


► Functions are used to avoid repetitive
#include<iostream>
task and also to save some memory
using namespace std;
space. However each time a function is
class Emp
{ called, it takes a lot of extra time in
private: executing a series of instructions for task
int emp_id; such as jumping to the function, saving
float salary; registers, pushing arguments into the
public: stacks and returning to the calling
void accept(); function.
void showdata(); ► To eliminate these problems C++
provides a new feature called inline
}; function.
void Emp::accept() ► “ An inline function is a function that is
{
expanded in line when it is invoked.”
cout<<"\n Enter Employee id : ";
That is the compiler replaces each
cin>>emp_id;
function call with the corresponding
cout<<"\n Enter Salary : ";
cin>>salary; function code.
} ► The functions defined inside the class
void Emp::showdata() definition are treated as inline.
{ ► One can define the function outside the
cout<<"\n Employee id is "<<emp_id; class and still make it inline using inline
cout<<"\n Employee salary is : key word.
"<<salary; ► Advantages of Inline functions:
} ► In line expansion makes a program run
int main() faster.
{ ► Disadvantage of inline functions:
Emp e;
► Takes more memory
e.accept();
► NOTE: The functions containing for loop
e.showdata();
or a function with a larger code are not
}
Output: made inline.
Executed with the help of Dev C++ ► If you make them inline compiler gives
you a warning.

Syntax : inline return- data-type function-


name ( Argument declaration)

function Body

Example:

inline double cube ( double a)

{
return ( a * a * a);

You might also like