Top Banner
1 FUNDAMENTALS OF COMPUTER APPLICATIONS AND INFORMATION TECHNOLOGY BY:- Er. USMAN GHANI S/O SHAKEEL AHMED MALERKOTLA DIST. SANGRUR PUNJAB (INDIA) STUDYING AT :- INSTITUTE OF ENGINEERING AND TECHNOLOGY, BHADDAL DIST. ROPAR PUNJAB [email protected] , [email protected]
55

FCPIT file for partial fulfilment of degree B.Tech. PTU

Apr 02, 2015

Download

Documents

Usman Ghani

Contains basic introduction to windows and MS-Word & containing main programs of c++
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: FCPIT file for partial fulfilment of degree B.Tech. PTU

1

FUNDAMENTALS OF COMPUTER

APPLICATIONS AND INFORMATION TECHNOLOGY

BY:-

Er. USMAN GHANI S/O SHAKEEL AHMED

MALERKOTLA DIST. SANGRUR PUNJAB (INDIA)

STUDYING AT :-

INSTITUTE OF ENGINEERING AND TECHNOLOGY, BHADDAL

DIST. ROPAR PUNJAB

[email protected] , [email protected]

Page 2: FCPIT file for partial fulfilment of degree B.Tech. PTU

2

CONTENTS Part A

Sr. No.

Chapter Page No. Remarks

1. Familiarization of computer system and on hand practice on power on and power off.

4

2. Loading window,closing , maximising 7 3. Saving file protecting unprotecting 8 4. Formatting floppies and practice on

virus recognition and protection 9

5. Practice with control panel 10 6. Practice with MS-Word, Operating

and closing document, Preparation of document, setting of document, familiarization with various tools, mail-merge practice.

11

Page 3: FCPIT file for partial fulfilment of degree B.Tech. PTU

3

Part B

C++ Programming

Sr. No. Contents Page no. Remarks 1. Write a program to add two no.s 17 2. Write a program to find the area of

square, rectangle and triangle 18

3. Write a program to interchange the value of two no.s without using third variable

19

4. Write a program to check whether the no. is prime or not

20

5. Write a program to find greatest of three no.s using nested if else

21

6. Write a program to display week days using switch statement

23

7. Write a program to print the following pattern * ** *** **** *****

25

8. Write a program to find the factorial of no. using while loop

26

9. Write a program to add the series of odd no.s

27

10. Write a program to print Fibonacci series

28

11. Write a program to compare two matrices

29

12. Write a program to multiply two matrices

31

13. Write a program to check whether a 33

Page 4: FCPIT file for partial fulfilment of degree B.Tech. PTU

4

string is palindrome or not 14. Write a program to reverse a string 35 15. Write a program to print bio data of

five students using structure 35

16. Write a program to swap two no.s by using passing by value and passing by reference

38

17. Write a program to find factorial of no. using recursion

39

18. Write a program to calculate and print smallest no. by using the concept of classes

40

19. Write a program to show multiple inheritance

43

20. Write a program to show use of parameterized constructor and copy constructor

44

21. Write a program to compute sum of two no.s using function overloading

47

22. Write a program to use unary and binary operator overloading

48

23. Write a program to display concept of pointers

52

Page 5: FCPIT file for partial fulfilment of degree B.Tech. PTU

5

Chapter 1

Familiarization of computer system

Computer:- A Computer is an electronis device that can perform a variety of operations in accordance with the set of instructions called program.

Functioning of computer:- The computer consists of mainly three parts namely Input system, Central Processing Unit & Output Unit. As shown in figure1

Figure 1

Input Unit:- The input unit is formed by the input devices attached to the computer. Examples of Input media are: keyboard, mouse, magnetic ink character reader, optical mark reader, optical character reader, joystick etc.

An input unit takes the input and converts it into binary form so that it can be understood by the computer.

Central Processing Unit(CPU):- The CPU is the control centre for the compuetr. It guides and governs the performance. It Consists of Arithmatic Logic Unit (ALU) & Control Unit (CU).

Output Unit:- The output unit is formed by the output units connected to the computer. It converts the computer understandable language into the human understandable language.

Page 6: FCPIT file for partial fulfilment of degree B.Tech. PTU

6

How To Powere On a PC:-

1. Switch on the main supply. 2. Switch on the UPS 3. Press the power button of CPU. 4. On the Monitor. 5. Enter the password 6. Now your computer is ready to Use.

How To Powere Off a PC:-

1. Click the start Button as shown in figure 2 2. Then Clich the shut down button as shown in figure 3 3. Then your compuetr is turned off.

Page 7: FCPIT file for partial fulfilment of degree B.Tech. PTU

7

Figure 2

Page 8: FCPIT file for partial fulfilment of degree B.Tech. PTU

8

Figure 3

Page 9: FCPIT file for partial fulfilment of degree B.Tech. PTU

9

Chapter 2

Loading window,closing , maximising

Closing window:-To close the window which in front of you have to move the mouse to the cross button(Figure 4) then click it, window will closed.

Figure 4

Maximising:-To maximise the icon you have to click the maximise button shown in Figure 4 at no. 2. The window will fit to screen.

Icon Shifting:-The icons can be shifted from one place to another by dragging and dropping them to other place.

Ordering:-Ordering of icons can be done by following method:-

1. Right click on the desktop at blank space the screen comes as show in Figure 5

2. Select the view.

3. Selct auto arrange from the sub menu.

The icons have been arranged.

Figure 5

Page 10: FCPIT file for partial fulfilment of degree B.Tech. PTU

10

Chapter 3

Saving file protecting unprotecting Saving Files:-When we made a file we must have to save it . Because if we do not save it it will be erased from the RAM .When we save the file it goes to the main memory of the computer. For example if we want to save the document in the word then we first select file and then save option, then select the location in the drive and click the save button.(Figure 6).

Protecting document:- To protect we have to follow the following steps (Figure 6):-

1. Select the file button

2. Select the save as option

3. Select the tools

4. Select the general options

5. Then write the password

Your document as been password protected.

Figure 6

Unprotecting document:-To unprotect the document open the security options and remove the password as shown in Figure 6.

Page 11: FCPIT file for partial fulfilment of degree B.Tech. PTU

11

Chapter 4

Formatting floppies and practice on virus recognition and protection Formatting floppy drive:-To format the floppy drive follow the following steps:-

1. Insert floppy into drive

2. Open the my computer

3. Right click on the floppy icon

4. Select the format option

5. Now select the type of format which you want

6. Click O.K.

Page 12: FCPIT file for partial fulfilment of degree B.Tech. PTU

12

Chapter 5

Practice with control panel

Control Panel:- It is the functioning part of computer which operates the settings of computer, in it we can set all the computer peripherals according to our need. To open the control panel follow simple steps:-

1. Click the START button

2. Click on the control panel.

3. Now u can manage the things shown in the control panel window(Figure 7).

Figure 7

Page 13: FCPIT file for partial fulfilment of degree B.Tech. PTU

13

Chapter 6 MS WORD

Word Processors are the class of software application that is designed for generating various

documents like letter, faxes, resume, memorandum and notices etc. Word Processing software provides

a set of tools and utilities for entering, editing and formatting text. In addition to typical word processing

tasks, modern word processors like MS Word, offer many interesting features like drawing various

objects, creating tables, inserting pictures and many more.

Features of MS word

MS word having following features: -

1. Microsoft Word offers easy editing of text.

2. Microsoft Word includes mail merge to create letters and labels.

3. Microsoft Word has a powerful spell checking facility.

4. Microsoft Word supports a wide number of paper sizes.

5. Microsoft Word has support for wizards and templates for automating tasks.

6. Microsoft Word has port for graphics and drawing objects.

Starting Word

To start word click once on the Start button, Choose Programs and click once on Microsoft

Office and then once on Microsoft Word.

Start Programs Microsoft Office Microsoft Word

Page 14: FCPIT file for partial fulfilment of degree B.Tech. PTU

14

Parts of MS-Word Window

TITLE BAR: It is the horizontal bar at the top of the window. It contains the name of the

current document. Until you save the document, WORD automatically assigns a name. The title

bar contains three buttons at its right end. These are the buttons to minimize, restore and close

the current window.

MENU BAR: It is a horizontal bar, below the title bar that contains several menus. Each of

these menus contains several MS WORD commands and utilities.

File: - the file menu displays the several menu commands .The file menu is used to perform a

variety of file and printing operations. The main menu selections or commands in the file pull

down menu are: - New, Open, save, Save as, Properties, Templates, Page setup, Print Preview,

print, send, Exit and some currently used and saved document files.

Edit: -The edits menu displays several menu commands like: -Cut, Copy, Paste, Clear, select all,

Find, Replace, Goto, Bookmark.

Page 15: FCPIT file for partial fulfilment of degree B.Tech. PTU

15

Window: - The window menu displays these commands: -New window, arrange all, split, and

some document filename.

Help: - Help menu displays: -Microsoft word help topics, Answer wizards,

STANDARD TOOL BAR: It is a horizontal bar that appears below the menu bar. It contains

shortcut command buttons. These buttons are the shortcuts to access standard menu

commands.

RULERS: Horizontal and vertical rulers appear on the top and left hand side of the page. They

help us to create and move the objects with accuracy.

PAGE AREA: The rectangular white area is the page of the document.

SCROLL BARS: Horizontal and vertical scrollbars are used to scroll the document to the left,

right, up and down.

DRAWING TOOLBAR: A horizontal bar at the bottom is called drawing toolbar. It contains

the several drawing tools.

STATUS BAR: Below the drawing toolbar, status bar is located. This bar depicts the status of

the current document. It displays the current page number, section number, and page

number/total number of pages in the document.

There are two types of windows:

(i) Application window: The area from the title bar till status bar.

(ii) Document window: The area between the ruler bar and the scroll bar

Page 16: FCPIT file for partial fulfilment of degree B.Tech. PTU

16

Opening an existing document

Go to file menu and click the open command or click on the open button of the standard toolbar

or press Ctrl+O from the keyboard.

Saving a Document

For this purpose either click the save command from the file menu or press Ctrl+S or move the

mouse pointer to the save button on the standard toolbar. A save as dialog box will be shown in which

type the file name in the filename box and click OK button. The word document is saved with .doc

extension.

Closing a current document

Go to file menu and click the Close command or press Alt+F+C from the keyboard.

Page 17: FCPIT file for partial fulfilment of degree B.Tech. PTU

17

Deleting a character

You can delete a character by moving the cursor to the desired location and press the Del key.

The del key deletes the character to the of cursor position. There is another key backspace key, which is

used to delete the character to left of the cursor position.

Inserting a character

You can insert a character by moving the cursor to the desired location with mouse or

keyboard so that the insert mode becomes on.

Cut, Copy, Paste Text (Moving and copying text):

To cut the text click the cut button from the standard toolbar or select the cut command from

the edit menu or press Ctrl+X key combination. To cut the desired text highlight the text by selecting it

and use any cut way. To copy the text by highlighting it then click the copy button from the standard

toolbar or select the copy command from the edit menu or press the Ctrl+C key combination from the

keyboard. Now you can paste the text by copy command. To paste the text move the cursor to the

desired location where you want to paste and click the paste button from the standard toolbar or select

the paste command from the edit menu or press Ctrl+V combination from the keyboard.

Centering the Text

Highlight the text by selecting it and click center button on the formatting toolbar or press

Ctrl+E combination from the keyboard.

Left Alignment of Text

Page 18: FCPIT file for partial fulfilment of degree B.Tech. PTU

18

If you want to set the selected text or paragraph or whole document at the left margin

alignment then first highlight the required text by selecting it, now either move the mouse pointer to

Align left button on the formation toolbar or press Ctrl+L key combination from the keyboard.

Right Alignment Of Text

First highlight the required text by selecting it. Now either move the mouse printer to Align right

button or the formatting toolbar or press Ctrl+R key combination from the keyboard.

Justify the Text

First highlight the required text by selecting it. Now either move the mouse pointer to the justify

button on the formatting toolbar or press Ctrl+J key combination from the keyboard.

Page Breaks

You can insert a manual page break any time you want to force Word to start a new page. To

insert a page break, move the cursor where you want to set the page break. You can select Break

command from the insert menu and click the break command.

Page 19: FCPIT file for partial fulfilment of degree B.Tech. PTU

19

Chapter 8

Programming in C++

1. Write a program to Add two no.s:-

#include<iostream.h>

#include<conio.h>

void main()

{

int a,b,c;

cout<<"Enter the value of a=";

cin>>a;

cout<<"Enter the value of b=";

cin>>b;

c=a+b;

cout<<"The Addition is="<<c<<endl;

getch();

}

Output:-

Page 20: FCPIT file for partial fulfilment of degree B.Tech. PTU

20

2.Write a program to find the Area of Triangle, Rectangle & Circle:-

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

float c,d,e,f,g,h,i,j;

cout<<"Enter the base of the triangle=";

cin>>c;

cout<<"Enter the altitude of the triangle=";

cin>>d;

e=(c*d)/2;

cout<<"Te area of triangle is="<<e<<endl;

cout<<"Enter the length of rectangle=";

cin>>f;

cout<<"Enter the breadth of rectangle=";

cin>>g;

h=f*g;

cout<<"The area of rectangle is="<<h<<endl;

cout<<"Enter the radius of the circle=";

cin>>i;

j=3.14*i*i;

cout<<"The area of circle is"<<j<<endl;

getch();

}

Page 21: FCPIT file for partial fulfilment of degree B.Tech. PTU

21

Output:-

3.Write a program to interchange the value of two no.s:-

#include<iostream.h>

#include<conio.h>

void main()

{

int a,b;

cout<<"Enter the value of a";

cin>>a;

cout<<"Enter the value of b";

cin>>b;

a=a+b;

a=a-b;

cout<<"The interchanged value of a is "<<b<<endl;

b=a+b;

b=a-b;

cout<<"The interchanged value of b is "<<a<<endl;

Page 22: FCPIT file for partial fulfilment of degree B.Tech. PTU

22

getch();

}

Output:-

4.Write a program to find number is prime or not:-

#include<iostream.h>

#include<conio.h>

void main()

{

int n,r,i,flag=0;

cout<<"ENTER A NUMBER";

cin>>n;

i=2;

while(i<=n-1)

{

r=n%i;

i++;

if(r==0)

{

cout<<"NUMBER IS NOT PRIME";

Page 23: FCPIT file for partial fulfilment of degree B.Tech. PTU

23

flag=1;

break;

}}

if(flag==0)

cout<<"NUMBER IS PRIME";

getch( );

}

Output:-

5.Write a program to find the greatest of three n o.s using nested if else:-

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int a,b,c;

cout<<"Enter the value of A";

cin>>a;

cout<<"Enter the value of B";

cin>>b;

cout<<"Enter the value of C";

Page 24: FCPIT file for partial fulfilment of degree B.Tech. PTU

24

cin>>c;

if(a>b)

{

if(b>c)

cout<<"The value of A is greatest";

else

cout<<" ";

}

else

{

if(b>c)

cout<<"The value of B is greatest";

else

cout<<"The value of C is greatest";

}

getch();

}

Output:-

Page 25: FCPIT file for partial fulfilment of degree B.Tech. PTU

25

6.Write a program to display week days using switch:-

#include<iostream.h>

#include<conio.h>

void main()

{

int a;

cout<<"Enter the day of week";

cin>>a;

switch(a)

{

case 1:

cout<<"Sunday";

break;

case 2:

cout<<"Monday";

break;

case 3:

cout<<"Tuesday";

break;

case 4:

cout<<"Wednesday";

break;

case 5:

cout<<"Thursday";

Page 26: FCPIT file for partial fulfilment of degree B.Tech. PTU

26

break;

case 6:

cout<<"Friday";

break;

case 7:

cout<<"Saturday";

break;

default:

cout<<"You have entered wrong day!";

}

getch();

}

Output:-

Page 27: FCPIT file for partial fulfilment of degree B.Tech. PTU

27

7.Write a program to printfollowing pattern:-

*

**

***

****

*****

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int i,j;

for(i=1;i<=5;i++)

{

for(j=1;j<=i;j++)

{

cout<<"*";

}

cout<<endl;

}

getch();

Page 28: FCPIT file for partial fulfilment of degree B.Tech. PTU

28

}

Output:-

8.Write a program to find factorial of no. usong while loop:-

#include<iostream.h>

#include<conio.h>

void main()

{

int a,i,fact=1;

cout<<"Enter integer:";

cin>>a;

i=a;

while(a)

{

fact=fact*a;

--a;

Page 29: FCPIT file for partial fulfilment of degree B.Tech. PTU

29

}

cout<<"The factorial of"<<i<<"is"<<fact<<"\n";

getch();

}

Output:-

9.Write a program to add odd terms:- #include<iostream.h>

#include<conio.h>

void main()

{ clrscr();

int n,sum=0,i=1;

cout<<"Enter a term till which you want to add odd no.s";

cin>>n;

do

{ sum=sum+i;

i=i+2;

Page 30: FCPIT file for partial fulfilment of degree B.Tech. PTU

30

}

while(i<=n);

{

cout<<"1+3+5+...""is"<<n<<sum; }

getch();

}

Output:-

10.Write a program to print fabonacci series:-

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

unsigned long first,second , third,n;

first=0;

second=1;

cout<<"How many elements";

cin>>n;

Page 31: FCPIT file for partial fulfilment of degree B.Tech. PTU

31

cout<<"Fibonacci series is"<<"n";

cout<<first<<" "<<second;

for (int i=2;i<n;++i)

{

third=first+second;

cout<<" "<<third;

first=second;

second=third;

}

getch();

}

Output:-

11.Write a program to compare of two matrices:-

#include<iostream.h>

#include<conio.h>

void main()

{

int A[2][2],B[2][2],r,c,flag=0;

cout<<"Enter the Elements of first matrix";

for(r=0;r<2;r++)

Page 32: FCPIT file for partial fulfilment of degree B.Tech. PTU

32

{

for(c=0;c<2;c++)

cin>>A[r][c];

}

cout<<"Enter the elements of second matrix";

for(r=0;r<2;r++)

{

for(c=0;c<2;c++)

cin>>B[r][c];

}

for(r=0;r<2;r++)

{

for(c=0;c<2;c++)

{

if(A[r][c]!=B[r][c])

{

flag=1;

break;

}

if(flag==1)

break;

}

}

if(flag==1)

cout<<"Matrices are unequal";

Page 33: FCPIT file for partial fulfilment of degree B.Tech. PTU

33

else

cout<<"Matrices are equal";

getch();

}

Output:-

12.Write a program to multiply two matrices:-

#include<iostream.h>

#include<conio.h>

void main()

{

int r,k,c,A[2][2],B[2][2],sum[2][2];

cout<<"Enter the elements of first matrix";

for(r=0;r<2;r++)

{

Page 34: FCPIT file for partial fulfilment of degree B.Tech. PTU

34

for(c=0;c<2;c++)

cin>>A[r][c];

}

cout<<"Enter the elements of Second matrix";

for(r=0;r<2;r++)

{

for(c=0;c<2;c++)

cin>>B[r][c];

}

for(r=0;r<2;r++)

{

for(c=0;c<2;c++)

{

sum[r][c]=0;

for(k=0;k<2;k++)

sum[r][c]=sum[r][c]+A[r][k]*B[k][c];

}}

cout<<"The multiplication of two matrices is ";

for(r=0;r<2;r++)

{

for(c=0;c<2;c++)

{

cout<<sum[r][c]<<endl;

}

Page 35: FCPIT file for partial fulfilment of degree B.Tech. PTU

35

getch();

}

}

Output:-

13.Write a program to check that string is palindrome or not:-

#include<iostream.h>

#include<conio.h>

#include<string.h>

#include<stdio.h>

void main()

{

char str[10];

int i,j,n,flag=0;

cout<<"Enter any string:"<<endl;

gets(str);

Page 36: FCPIT file for partial fulfilment of degree B.Tech. PTU

36

n=strlen(str);

for(i=0,j=n-1;i<=n/2;i++,j--)

{

if(str[i]!=str[j])

flag=1;

break;

}

if(flag==1)

cout<<"String is not Palindrome";

else

cout<<"The string is Palindrome";

getch();

}

Output:-

Page 37: FCPIT file for partial fulfilment of degree B.Tech. PTU

37

14.Write a program to reverse a string:-

#include<iostream.h>

#include<conio.h>

#include<string.h>

#include<stdio.h>

void main()

{

char str[10];

cout<<"Enter any string:"<<endl;

gets(str);

strrev(str);

cout<<"The reversed string is:"<<endl<<str;

getch();

}

Output:-

15.Write a program to print biodata of student using structures:-

#include<iostream.h>

#include<conio.h>

Page 38: FCPIT file for partial fulfilment of degree B.Tech. PTU

38

void main()

{

clrscr();

{

struct biodata

{

char name[80];

int rollno;

char branch[80];

int semester;

};

biodata student[5];

cout<<"Enter boidata of 5 students"<<endl;

for (int i=0;i<=4;i++)

{

cout<<"Enter name";

cin>>student[i].name;

cout<<"Enter roll_no."<<endl;

cin>>student[i].rollno;

cout<<"Enter branch"<<endl;

cin>>student[i].branch;

cout<<"Enter semester"<<endl;

cin>>student[i].semester;

}

Page 39: FCPIT file for partial fulfilment of degree B.Tech. PTU

39

for(i=0;i<=4;i++)

{

cout<<"Name:"<<student[i].name<<endl;

cout<<"Roll no:"<<student[i].rollno<<endl;

cout<<"Branch:"<<student[i].branch<<endl;

cout<<"Semester:"<<student[i].semester<<endl;

}

getch();

}}

Output:-

Page 40: FCPIT file for partial fulfilment of degree B.Tech. PTU

40

16.Write a program to swap two no.s using passing by value and passing by reference:-

#include<iostream.h>

#include<conio.h>

void main()

{

int x,y;

void swap(int,int);

clrscr();

cin>>x;

cin>>y;

swap(x,y);

cout<<"x="<<x<<endl;

cout<<"y="<<y<<endl;

getch();

}

void swap(int a,int b)

{

int temp;

temp=a;

a=b;

b=temp;

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

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

}

Page 41: FCPIT file for partial fulfilment of degree B.Tech. PTU

41

Output:-

17.Write a program to find factorial of no using recursion:-

#include<iostream.h>

#include<conio.h>

void main()

{

int fact(int);

int f,n;

cout<<"Enter the value to find factorial";

cin>>n;

f=fact(n);

cout<<"Factorial is"<<f<<endl;

getch();

}

int fact (int n)

{

int value=1;

if (n==1)

Page 42: FCPIT file for partial fulfilment of degree B.Tech. PTU

42

return value;

else

{

value=n*fact(n-1);

return value;

}}

Output:-

18.Write a program to calculate and print smallest of two no.s using concept of classes:-

#include<iostream.h>

#include<conio.h>

class a

{

private:

int a,b;

public:

void get()

Page 43: FCPIT file for partial fulfilment of degree B.Tech. PTU

43

{

cout<<"Enter the value of a";

cin>>a;

cout<<"Enter the value of b";

cin>>b;

}};

class b

{

private:

int a,b;

public:

void show()

{

if(a<b)

cout<<"B is smallest";

else

cout<<"A is smallest";

}};

void main()

{

a obj;

b obj1;

obj.get();

obj1.show();

Page 44: FCPIT file for partial fulfilment of degree B.Tech. PTU

44

}

Output:-

19.Write a program to show multiple inheritance:-

#include<iostream.h>

#include<conio.h>

class a

{

public:

void getdata()

{

cout<<"This is base class a"<<endl;

}};

class b

{

public:

void getdata1()

{

cout<<"This is base class b"<<endl;

}};

class c

Page 45: FCPIT file for partial fulfilment of degree B.Tech. PTU

45

{

public:

void getdata2()

{

cout<<"This is base class c"<<endl;

}};

class m:public a,private b,protected c

{

public:

void getdata3()

{

cout<<"This is multiple inheritence"<<endl;

}};

void main()

{

clrscr();

a obj;

b obj1;

c obj2;

m obj3;

obj.getdata();

obj1.getdata1();

obj2.getdata2();

obj3.getdata3();

Page 46: FCPIT file for partial fulfilment of degree B.Tech. PTU

46

getch();

}

Output:-

20.Write a program to show use of parametric constructor and copy constructor:-

#include<iostream.h>

#include<conio.h>

class xyz

{

public:

int a,b,c;

xyz(int x, int y)

{

a=x;

b=y;

}

void sum()

{

c=a+b;

cout<<c;

}};

Page 47: FCPIT file for partial fulfilment of degree B.Tech. PTU

47

void main()

{

clrscr();

int a,b;

cout<<"Enter the value of a";

cin>>a;

cout<<"Enter the value of b";

cin>>b;

xyz m(a,b);

m.sum();

getch();

}

Output:-

Copy constructor:-

#include<iostream.h>

#include<conio.h>

class abc

{

private:

int a;

float b;

Page 48: FCPIT file for partial fulfilment of degree B.Tech. PTU

48

public:

abc(int x,float y)

{

a=x;

b=y;

}

abc(abc &m1)

{

a=m1.a;

b=m1.b;

}

void write()

{

cout<<a<<b;

}};

void main()

{

clrscr();

int a;

float b;

cout<<"Enter the value of a";

cin>>a;

cout<<"Enter the value of b";

cin>>b;

abc m1(a,b);

Page 49: FCPIT file for partial fulfilment of degree B.Tech. PTU

49

abc m2=m1;

m2.write();

getch();

}

Output:-

21.Write a program to compute sum using the concept of function overloading:-

#include<iostream.h>

#include<conio.h>

int sum(int a,int b)

{

return a+b;

}

float sum(float a,float b)

{

return a+b;

}

void main()

{

int i,j;

Page 50: FCPIT file for partial fulfilment of degree B.Tech. PTU

50

float k,l;

int sum(int,int);

float sum(float,float);

cout<<"Enter the value of two integers";

cin>>i>>j;

cout<<"Sum of integers is"<<sum(i,j)<<endl;

cout<<"Enter the value of two floats";

cin>>k>>l;

cout<<"Sum of floats is"<<sum(k,l);

getch();

}

Output:-

22. Write a program to use concept of operator overloading

(a)Unary Operator:-

#include<iostream.h>

#include<conio.h>

class complex

{

int r;

Page 51: FCPIT file for partial fulfilment of degree B.Tech. PTU

51

int i;

public:void getdata()

{

cout<<"enter real part";

cin>>r;

cout<<"enter imag part";

cin>>i;

}

void operator++()

{

++r;

++i;

}

void showdata()

{

cout<<r<<"+ i"<<i<<endl;

}

};

void main()

{

complex C1;

clrscr();

Page 52: FCPIT file for partial fulfilment of degree B.Tech. PTU

52

C1.getdata();

cout<<"number before increment "<<endl;

C1.showdata();

++C1;

cout<<"number after increment"<<endl;

C1.showdata();

getch();

}

Output:-

(b)Binary operator:-

#include<iostream.h>

#include<conio.h>

class myclass

{

private:

int s1,s2;

public:

Page 53: FCPIT file for partial fulfilment of degree B.Tech. PTU

53

myclass(int x,int y)

{

s1=x;

s2=y;

}

void show()

{

cout<<s1<<endl<<s2;

}

myclass operator +(myclass m)

{

//myclass temp;

s1=s2 +m.s1;

s2=s2+m.s2;

return myclass (s1,s2);

}};

void main()

{

clrscr();

myclass m1(50,40);

myclass m2(40,50);

//myclass m3;

m1=m1+m2;

m1.show();

Page 54: FCPIT file for partial fulfilment of degree B.Tech. PTU

54

getch();

}

Output:-

23.Write a program to display concept of pointers:-

#include<iostream.h>

#include<conio.h>

void main()

{

int *p;

int x;

clrscr();

cout<<"Enter a value";

cin>>x;

p=&x;

*p=*p+10;

cout<<"Now x is"<<x<<endl;

cout<<"Value of x through p"<<*p<<endl;

Page 55: FCPIT file for partial fulfilment of degree B.Tech. PTU

55

cout<<"The address of x is"<<&x<<endl;

cout<<"The address of x through p"<<p<<endl;

getch();

}

Output:-