IoE (Institute of Engineering)

The Institute of Engineering, established in 1930, is the first technical school of Nepal. It was reformed in the present shape in 1972 as an organ of Tribhuvan University. Besides producing low and tertiary level technicians, IOE runs professional diplomas, undergraduate, postgraduate and Ph.D. programs.

Electrical Club Members of NCE

IOE ELECTRICAL CLUB is the team of electrical students studying at IOE. The group was established to fascilate the students to share their ideas regarding electrical technology and electrical projects. The club helps students to support and guide the projects in which they are engaged in

Various Sports Awards

The Nepal national basketball team represents Nepal in international basketball competitions and is managed by the NCE College.

Wireless Electric Vehicle Charging Technology

Wireless electricity is quite literally the transmission of electrical energy without wires.The principle behind the Tesla coil is to achieve a phenomenon called resonance.The massive amount of energy makes the magnetic field collapse quickly, and generates an electric current in the secondary coil.

Winner

“No man needs sympathy because he has to work, because he has a burden to carry. Far and away the best prize that life offers is the chance to work hard at work worth doing.”

Showing posts with label BEL2068OOPRegular. Show all posts
Showing posts with label BEL2068OOPRegular. Show all posts

C++ IOE Note By Anup sir(IOE Pulchowk all subject note )

C++ IOE Note By Anup sir(IOE Pulchowk blog)


http://notepulchowkcampus.blogspot.com/
C++ note

 Click Below to Download Full Note by Anup Shretha sir in PDF or Read below in blog (IOE Best teacher at C++)
http://notepulchowkcampus.blogspot.com/
Click Me




Exception Handling:

It is required to develop a fault tolerance software system.  If a software program is provided with exceptional handling mechanism then the software will smoothly run in spite of presence of fault.

Exception handling mechanism generally uses three keywords they are:

try , catch and throw statement.

è The part of code that generate the exception should be placed in try block.

è if any exception occurs then it is thrown using throw keyword

è the exception handling code or mechanism is placed in catch block.

  • Example 1 of exception handling in c++ :
  • Example of exception handling in oop :

#include<iostream>

#include<conio.h>

using namespace std;

int main()

{

int a,b,x;

cout<<"Work: a/(a-b)\nEnter the value of a and b"<<endl;

cin>>a>>b;

x=a-b;

try

{

if (x!=0)

{

cout<<"\nThe division is "<<a/x<<endl;

}

else

{

throw(x);

}

}

catch(int y)

{

cout<<"\nException is found"<<"Division can not occur by zero difference"<<y<<""<<y;

}

 

return 0;

}

 

 

 

https://notepulchowkcampus.blogspot.com/
exception handling in c++ :

 

 

 

  • Example 2 of exception handling in c++
  • Example 2 of exception handling in oop

#include<iostream>

#include<math.h>

using namespace std;

int main()

{

                float x;

                int a;

                cout<<"\nEnter number"<<endl;

                cin>>a;

                try

                {

                                if( a>0)

                                {

                                                x=sqrt(a);

                                                cout<<"\nSquare root  of "<<a<<"is "<<x<<endl;

                                }

                                else

                                {

                                                throw(a);

                                }

                }

                catch(int x)

                {

                                cout<<"Square root of negative number "<<a<<" is not possible"<<endl;

                }

                return 0;

}

Re throwing exception:

if we can not handle the exception completely i.e. caught by catch block then we rethrow that exception by using throw keyword only without using any argument. This is called re throwing exception.

this cause the current expression to be pass into the out of try catch block;

  • Example of re throwing exception.in c++:

#include<iostream>

using namespace std;

int main()

{

                int a,b,x,c;

                cout<<"Enter the value of a and b"<<endl;

                cin>>a>>b;

                x=a-b;

                try{

                                if(x!=0)

                                {

                                                cout<<"The resul is "<<(a/x)<<endl;

                                }

                                else

                                {

                                                throw(x);

                                }

                }

                catch(int x)

                {

                                cout<<"\nException Found\n";

                                throw;

                }

                return 0;

}

Catching all exception:

in c++ there is provision of catching all exception raised in try block of code without considering their data type. This provision is known as catching all exception.

in other word catching all exception will catch all the exception of any data type raised from try block.

  • syntax for catching all exception:

catch(…)

{

                //handling all type of exception

}

  • Example of catching all exception in c++:

#include<iostream>

using namespace std;

void function(int test)

{

                try

                {

                                if (test==0)

                                {

                                                throw(test);

                                }

                                else if (test==1)

                                {

                                                throw(1);

                                }

                                else if (test==2)

                                {

                                                throw(2);

                                }

                                else

                                {

                                                cout<<"\nCalled function other than 0, 1,2";

                                }

                }

                                catch(...)

                                {

                                                cout<<"All Exception Caught";

                                }

               

}

int main()

{

                cout<<"\nCalling function with 0";

                function(0);

                cout<<"\nCalling function with 1";

                function(1);

                cout<<"\nCalling function with 2";

                function(2);

                cout<<"\nCalling function with 3";

                function(3);

                return 0;

}

 

 

Multiple handling

In C++ there is provison of handling multiple exception that is generated from  try block 

but in the case of multiple handler we use separate catch block to handle exception of each data type.

  • Example of multiple handling in c++

catch (int a)

{

cout<<"integer found"<<endl;

}

catch (char ch)

{

cout<<"character  found"<<endl;

}

catch (float c)

{

cout<<"float  found"<<endl;

}

 #allnoteofexceptionhandlinginc++,#exceptionhandlinginc++,#exception handling in c++

https://notepulchowkcampus.blogspot.com/


Share:

OOP C++ IOE NOTE NCE NOTE

C++ IOE Computer Electrical OOP Note for final exam for 32 Mark conform


C++ IOE Computer Electrical OOP Note for final exam for 32 Mark conform

Inline function: 

It is the function that is expanded inline when it is called with corresponding code. The syntax for making inline is inline return-type function-name(no arguments/arguments) 

Note:- inline function should always have return type.

Advantage: 
  • It reduces the exception time of a program with function having fewer lines of codes.
Disadvantage: 

  • The execution time of inline function is more than normal function if the function has the larger number of codes or more lines of code. 
  • It does not work for the recursive course. 

Default Arguments:

 C++ allows programmers to call a function without specifying all its arguments. In such case function assigned a default value to the parameters which does not have matching arguments in function call. These value in function definition are called default arguments. 

Note: while assigning a default value , we should place the default from right to left. 

eg:- 

  • float simple (int P, int t, float r=0.15) (default argumernt or legal) 
  • float simple(int p, int t=2,float r) (illegal) 
  • float simple(int p, int t=2,float r=0.15) (legal) 

Inline and default arguments: 

C++ IOE Computer Electrical OOP Note for final exam for 32 Mark conform

function overloading:

function overloading means using same function name to perform variety of task. But in function overloading we must consider two things. They are:

  • 1.       Either the number of arguments in function should be different (the number of input to function should vary).
  • 2.       if the number of arguments are same then the data type of the function arguments should be different number of parameter  different.

Note: return type has no role in function overloading

int sum(int a, int b)

{

return (a+b);

}

int sum(int a1, int b1, int c1)

{

return(a1+b1+c1);

}

int sum(int d)

{

return (d+5);

}

void main()

{

cout<<"The sum of one variable"<<sum(10)<<endl;

cout<<"The sum of two variable"<<sum(10,20)<<endl;

cout<<"The sum of three vriable"<<sum(10,20,30)<<endl;

getch();

}

Q. write a program to calculate the area of rectangle and triangle using concept of function overloading.

type II

#include<iostream.h>

#include<conio.h>

using namespace std;

int area(int l, int b)

{

return (l*b)

}

float area(int b, float h)

{

return (0.5*b*h);

}

void main()

{

int l1,b1;

float  h;

cout<<"Enter the value of l1,b1 & h1<<endl;

cin>>l1>>b1>>h1;

cout<<"The area of rectangle is <<area(l1,b1)<<endl;

cout<<"The area of triangle is<<area(l1,h1);

getch();

}

 Reference variable:

Ans:  Is an alternative name given to the original variable. any changes made to reference variable will change original variable and vice versa.

the syntax for making reference variable is:-

data-type & reference_variable = original variable

eg:- int &a(reference variable)=X(original variable)

#include<iostream.h>

#include<conio.h>

using namespace std;

void main()

{

int x=5;

int &a=x; // making refrance variable

a=a+5;

cout<<"The value of x is"<<x<<endl;

getch();

}

output =10

                            

Q. is the concept of alternative variable used for pass by reference ? if yes show with an appropriate example.

Ans: pass by reference: provision of reference variable in c++ allows us to pass parameter to the function by reference. when we pass argument by reference the formal argument in the function call (the input variable of function definition) becomes alternative variable ( or reference variable) of the variable in function call.

#include<iostream.h>

#include<conio.h>

using namespace std;

void swap (int &a, &b)

{

int temp=a;

a=b;

b=temp;

}

void main()

{

int x1=5,y1=6;

cout<<"before swapping x1="<<x1<<endl<<"y1="<<y1<<endl;

swap(x1,y1);    // function call

cout<<"After swapping"<<"x1="<<x1<<endl<<"y1"<<y1<<endl;

getch();

} 

Q. wap to calculate area and perimeter of rectangle in a function and display the result in main().

#include<iostream.h>

#include<conio.h>

using namespace std;

void rectangle(int l, int b, int &A1, int &P1)

{

A1=l*b;

P1=2*(l+b);

}

void main()

{

int l1,b1,A,P;

cout<<"Enter the value of l1 and b1"<<endl;

cin>>l1>>b1;

rectangle (l1,b1,A,P);

cout<<"Area of rectangle is "<<A<<endl<<"Perimeter of rectangle is"<<P<<endl;

getch();

}

 

Return by reference: 

In return by reference in true case c++ assign a reference value . in return by the function is called as:

syntax: function call = reference value;

eg:-

Max(a,b)=200; (reference value  )

the syntax for function definition in return by reference is

return-type & function_name(data_type1 & variable1,data type2 and variable 2...... upto n)

example of return by reference:

 #include<iostream.h>

#include<conio.h>

using namespace std;

int &Max(int &a, int &b)

{

if (a>b);

{

return (a);

}

else

            {

            return (b);

            }

}

void main()

{

int a=10, b=5;

Max(a,b)=200;  // function call

cout<<"a="<<a<<endl<<"b="<<b<<endl;

getch();

}

output: a=10, b=5

Q. How memory is allocated dynamically for normal variable and array?

Ans: Memory is allocated dynamically for normal variable by using syntax:-

pointer-variable = new data type

eg:-

int *p;

p=new int;

alternatively we can combine to allocate dynamically

syntax: data-type *pointer variable = new data type

 

for array

syntax

data type *pointer = new data type (size)

eg:-

int *p = new int [20];

 

class and object:

class:

  • 1.       a class is a way to bind data and associated function together.
  • 2.       it allows data and function to hidden if necessary for external use.
  • 3.       defining a class means creating a user defined data type that behaves as built in data.
  • 4.       once a class has been declared we can create any number of object belonging to that class.

syntax:

class class_name

{

private:

data member;

member function;

public:

data member;

member function;

};          //end of class

 

Generally data are placed in private section and function are placed in public section.

  • 5.       class contains both data and function . Data are called data member and function are called member function.
  • 6.       data and function are defined in private section are not accessible out of the class.
  • 7.       data and function placed in public section are only accessible from outside the class.
  • 8.       the word private is optional . the data in function of class by default private.

object:

  • ð  object are the basic entities of oop. the object may be person place or anything's that have some physical attribute. Object are the variable of class in terms of programming.

syntax:

class_name objects_name(variable name)

Share:

2068 Chaitra OOP pulchowk campus engineering note

2068 Chaitra Regular engineering note
https://notepulchowkcampus.blogspot.com/

2068 Chaitra Regular Object-Oriented Programming IOE Pulchowk engineering note


1. What is encapsulation? What are its advantages? How can encapsulation be enforced in C++? Write a program to create a class Land Measure that reads Ropani, Ana, Paisa and Dam as data members. Write a function to pass two objects of type Land Measure and return their sum. (16 Ana - 1 Ropani, 4 Paisa = 1Ann, 4 Dam- 1 Paisa).

2. What is function overloading? Use new and delete operators to store numbers dynamically and find their average using casting operators. What are the things we should remember while using the default argument? Explain with an example.

3. What do you mean by friend function and friend class? Do friends violate encapsulation? Write a program that can store Department ID and Department name with constructors. Also, write destructor in the same class and show that objects are destroyed in reverse order of creation with a suitable message.

4. List the operators which cannot be overloaded. Why does the overloading of a binary operator with member function require only one argument? Create a class having an array as a member. Overload the index operator ([ ]) to input and display the elements in the array.

5. How do you access an overridden member of the base class from a member function in the derived class? What is the problem faced when using multipath inheritance and how is it solved. Explain with an example the order of constructor and destructor invocation during multiple inheritances.

6. What are the primary trade-offs between static and dynamic binding? What is pure virtual function? Write a function template for the function power() which has two parameters baseexp. The type of base is the parameter to the template and exp is int. If the exp is negative, then it must be converted to its positive equivalent. For example, 23and 2-3  must both return 8.

7. What is a file stream? Write a class student with roll, name, address, marks as member variables Use a member function to write a record of students in a binary file and another member function to read records from file. Write a program to search a specific record of a student using roll numbers as key from user input.

8. What are the advantages of Exception Handling over Conventional Error Handling mechanism? Explain the contracts for Exception Handling in C++with an example. Write a meaningful program to illustrating the use of both Exceptions with argument and Exception Specification for function.

Share:

subscribe

IOE ALL SUB NOTES

Delivered by FeedBurner

Wikipedia

Search results

The quality of being the only one of its kind.

If you are fresher or preparing to attempt the Back Exam then you are going to be happy to know that here you will find all the shortlisted targeted question for your subject. Here you will find perfect answers to your questions