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

CERTIFICATE

This is to certify that Mr. Piyush kadale student of B.Sc(Animation.)


Semester FY having Seat No. 016 at Suryadatta College of Management
Information Research & Technology (SCMIRT), Pune, has successfully
completed the assigned practical in Introduction to Programming
Languages. prescribed by the University of Pune During the academic year
2018/19.

Internal Examiner External Examiner

Principal
Place: Pune Date:
Suryadatta College Of Management Information Research & Technology

Index

Student's Faculty's
Sr. No. Practical Name Pg No. Date Remark
Sign Sign
1
Subject a nd pecenta ge a l s o pri nt pa s s or fa i l

2
Area a nd peri meter a nd s qua re a nd recta ngl e

3
Ma xi mum no. a nd s qua re of ma xi mum no.

4
Check wether no. i s pri me or not

5
GCD of two i ntegers

6
Addi ti on of a rra y el ements

7
Fi nd a n el ement i n a rra y

8
Ca l cul a te n fa ctori a l

9
Stri ng l i bra ry functi on

10
Fi bona cci s eri es from fi rs t 25 numbers

11
Swi tch ca s e performs ma ths opera ti on

12
2 di mens i ona l a rra y i n ma tri x

13
Demons tra te us e of s tructure to fi nd s tudents na me

14
Cl a s s s tri ng us i ng di fferent cons tructor

15
Cl a s s a nd member funti on us e of a rra y objects

16
Crea te cl a s s us i ng functi on overl oa di ng

17
Two cl a s s es us i ng functi on overl oa di ng

18
Us i ng functi on overl oa di ng

19
Mul ti l evel i nheri ta nce to s tore s tudent i nforma ti on

20
Runti me pol ymorphi s m
Start date: Practical no:

Que1.Write a Program which take a input marks obtain in 4 subject and print marks obtain in

Subject and percentage (in float) also print student is pass or fail (student is fail if he/she

Obtain less than 35 marks in any of four papers

SOURCE CODE:

#include<stdio.h>

#include<conio.h>

Void main()

Clrscr();

int chem,phys,IT,maths;

float T,total,per;

printf(“Enter the marks “);

scanf(“%d” &chem,”%d” &phys,”%d” &IT, “%d” &maths);

total=chem.+phys+IT+maths;

printf(“total is %f”,total);

T=400;

per=(total/T)*100;

Printf(“percentage is %f”,per):

if(per>=35)

printf(“congrats”);

else

printf(“sorry”);

getch();

}
OUTPUT:

Enter the marks =35

35

35

35

Total marks=140

Percentage=35%

Congrats

End date: Faculty Signature


Start date: Practical no:

2. Write a C program find the Area and Perimeter and Square and Rectangle

SOURCE CODE:

#include<stdio.h>

void main()

clrscr();

int length,breadth,peri,area,side,peri2,area2;

printf(“Enter the length and brreadth of the rectangle=”);

scanf(“%d” &length,”%d” &rectangle”);

area=length*breadth;

peri=(2*length)+(2*breadth);

printf(“Area=%d perimeter=%d”,area,peri);

printf(“Enter the length of side of square=”);

scanf(“%d” ,&side);

area2=side*side;

peri2=4*side;

printf(“Area2=%d perimeter=%d,area2,peri2);

getch();

}
OUTPUT:

Enter the length and breadth of the recrangle=6

Area=24 perimeter=28

Enter the length of a side of square=6

Area =36 perimeter=24

End date: Faculty Signature


Start date: Practical no:

3. Write a C program find the find max, Among 3 integer numbers. And also print square of

the maximum number

SOURCE CODE:

#include<stdio.h>

void main()

int a,b,c;

clrscr();

printf(“Enter three no.=”);

scanf(“%d” &a,”%d” &b,”%d” &c);

if(a>b&&a>c)

printf(“a is highest and square of a is=”;a*a);

else if(b>a&&b>c)

printf(“b is highest and sqaure of b is=”,b*b);

else

Printf(“c is highest and square of c is=”,c*c);

getch();
}

OUTPUT

Enter the numbers a,b,c

2=4,8=64,1=1

8=64 is the largest number

End date: Faculty Signature


Start date: Practical no:

4. Write a C program to check whether the number is prime or not(Write a function to check

number is prime).

SOURCE CODE:

#include<stdio.h>

#include<conio.h>

void main()

clrscr();

int n,i,ans;

printf("enter the numbers");

scanf("%d",&n);

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

ans=n%i;

if(ans==0)

printf("not prime number",ans);

else

printf("yes number is prime",ans);

getch();

}
OUTPUT:

Enter the numbers 23

Yes number is prime

End date: Faculty Signature


Start date: Practical no:

5. write a C program to print GCD of two integers

(Write a function to find GCD).

SOURCE CODE:

#include<stdio.h>

void main()

int n,m,i,gcd;

printf(“Enter two integers=”);

scanf(“%d” &n,”%d” &m);

for(i=1;i<=n&&i<=m;i++)

//check whether i is factor of both integers

if(n%i==0&&m%i==0)

gcd=i;

printf(“%d %d %d”,n,m,gcd);

getch();

OUTPUT:

Enter the two integers

30

40

GCD of two integrs =10

End date: Faculty Signature


Start date: Practical no:

6. Write a C program to print addition of Array elements.

(Number of array element will be 5 and take the array element from user)

SOURCE CODE:

#include<stdio.h>

void main()

int a[5],i,sum=0;

clrscr();

printf(“Enter five array elements=”);

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

scanf(“%d”,&a[i]);

For(i=0;i<=5;i++)

sum=sum+a[i];

printf(“Addition of array elements=%d”,sum);

getch();

}
OUTPUT:

Enter five array elements

5,5,5,5,5

Sum=25

End date: Faculty Signature


Start date: Practical no:

7. Write a C program to find an element in array.

(Number of array element will be 5 and take the array element from user)

SOURCE CODE:

#include<stdio.h>

#include<conio.h>

void main()

clrscr();

int a[10],size,i,search,flag;

printf("enter size of array");

scanf("%d",&size);

printf("enter %d element of array",size);

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

scanf("%d",&a[i]);

printf("please enter the search element");

scanf("%d",&search);

flag=0;

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

if(a[i]==search)

flag=1;
break;

if(flag==1)

printf("search element %d at position %d",search,i+1);

else

printf("sorry");

getch();

OUTPUT:

size of array=10

elements in array:10 12 20 25 13 10 9 40 60 5

element to search is=25

elements found at index=3

End date: Faculty Signature


Start date: Practical no:

8. Write a C program to calculate n! Factorial.

SOURCE CODE:

#include<stdio.h>

void main()

int c,n,fact=1;

printf(“Enter a number to calculate its factorial\n”);

scanf(“%d”,&n);

for(c=1;c<=n;c++)

fact=fact*c;

printf(“Factorial of %d=%d\n”,n,fact);

getch();

OUTPUT:

Enter the number:5

Factorial=120

End date: Faculty Signature


Start date: Practical no:

9. Write a C program to read two strings and explain string library function.

1)strlen()

2)strcyp()

3)strcat()

SOURCE CODE:

1:#include<stdio.h>

#<string.h>

voi d main()

char s1[10];

int l;

clrscr();

printf(“Enter the string=”);

get s(s1);

l=strlen(s1);

printf(“length=%d”,l);

getch();

OUTPUT:
2.#include<stdio.h>

#include<string.h>

void main()

char s1[10],s2[20];

clrscr();

s1=amu

s2=omkar

strcpy(s1s2);

printf(“First string=”);

puts(s1);

printf(“Second string=”);

puts(s2);

getch();

OUTPUT:

First string=amu

Second string=omkar
3.#include<stdio.h>

#include<string.h>

void main()

char s1[10],s2[20];

clrscr();

printf(“Enter the first string=”);

gets(s1);

printf(“Enter the second string=”):

gets(s2);

strcat(s1,s2);

printf(“First string=”);

puts(s1);

printf(“Second string=”);

puts(s2);

getch();

OUTPUT:

Enter the first string=James

Enter the second string=Bond

James Bond

End date: Faculty Signature


Start date: Practical no:

10.Write a C program to which contain function to obtain first 25 numbers of a Fibonacci series.

SOURCE CODE:

#include<stdio.h>

#include<conio.h>

void main()

clrscr()

int n, i, a=0,b=1,c;

printf("Enter a number=");

scanf("%d" ,&n);

for (i=1,i<=n ; i++)

c=a+b;

printf("%d,"c);

a=b;

b=c;

getch();

}
OUTPUT:

Enter a number=25

0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,

End date: Faculty Signature


Start date: Practical no:

11. Write a C program using switch case which perform math’s operation (+,-,*, /, %)

SOURCE CODE :

#include<stdio.h>

void main()

char a ,b ,c , ch;

clrscr();

printf("Accept number 1");

scanf("%d", &a);

printf("Accept number 2");

scanf("%d", &b);

printf("Enter the choice '+'-Addition/n, '-'-Subtraction/n, '*'-Multiplication/n, '/'-Division/n, '%'-


percentage)

scanf("% s, &ch);

switch(ch)

{
case +: c=a+b

printf ("Addition=%d",c);

break;

case - : c=a-b;

printf("Subtraction=%d",c);

break;

case * : c=a*b;

printf("Multipication=%d",c);

break;
case / : c=a/b;

printf("Division=%d",c);

break;

case % : c=a%b

printf("Modular = %d",c);

break;

default : printf("Invalid choice");

break;

getch();

OUTPUT:

Enter two numbers : 6

1.Addition

2.Subtraction

3.Multiplication

4.Division

Enter your choice : 4

Result=0.857143.

End date: Faculty Signature


Start date: Practical no:

12. Write a C program to display an element of 2 dimensional arrays in matrix form. (Array

size is 3x3 and takes the array element from user)

SOURCE CODE:

#include<stdio.h>

void main()

int a[3][3],i,j;

clrscr();

printf(“Enter a matrix);

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

for(j=0;j<3;j++)

scanf(“%d”,&a[i][j]);

printf(“matrix=”);

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

for(j=0;j<=3;j++)

printf(“%d/t”,a[i][j]);

printf(“\n’);
}

getch();

OUTPUT:

Enter number of row for array :3

Enter the number of column for array:3

Enter the matrix:1

Array=

1 2 3

4 5 6

7 8 9

End date: Faculty Signature


Start date: Practical no:

13. Write a C program demonstrate use of structure declare following structure and write m

menu driven program display student info and to find student name in data

SOURCE CODE:

#include<stdio.h>

#include<string.h>

strct student

{
int id;

char name [50];

s1,s2;//declaring S1 and S2 variables for structure

int main ()

//store first student information

s1.id=101;

strcpy(s1.name,”Rahul”);//copying string into char array

//S2.id=102;

strcpy(s2 name ,”Itachi Uchiha”);

//printing first student information

printf(“student 1 id:%d\n”,S1.id);

printf(“student 1 name : %s\n”,S1.name);

//printing second student information

printf(“student 2 id:%d\n”,s2.id);

printf(“student 2 name:%s\n”,s2.mane);

return 0;
}

OUTPUT:

Student s1= Rahul

Student s2= Itachi Uchiha

End date: Faculty Signature


Start date: Practical no:

14. . Define a class string. Use different constructors and do the following [20

marks]

- Create un-initialized string objects

- Create objects with string constants

- Concatenate two strings

- Display desired strings

SOURCE CODE:

#include<iostream.h>

#include<string.h>

using namespace

int main()

String str1=”hello”;

String str2=”world”;

String str3;

int len;

//copy str1 into str3

Str3=str1;

Cout<<”str3;”<<str3<<endl;

//total length od str3 after concatenation

Len=str3,sice();

Cout<<:str3.size():”<<len<<endl;

return 0;

}
OUTPUT:

String=helloworld

Size=10

End date: Faculty Signature


Start date: Practical no:

16. Write necessary class and member function definitions for a cricket player object.

(Use array of objects).

The program should accept details from user (max 10) : player code, name, runs,

Innings, played, number of times not out.

The program should contain following menu:

• Enter details of players.

• Display average runs of a single player.

Average runs of all players.

SOURCE CODE:

#include<iostream.h>

#include<string.h>

#include<conio.h>

using namespace std;

class scorecard

Char batname[11][20];

int runscored[11];

char situation[11][20];

char mode[11][15];

char bowlernamned[11][20];

float oversplayed[11];

int maiden[11];

int runsgiven[11];
int wicketstaken[11];

public:

void updatebatman(void);

void updatebowler(void);

void displaybat(void);

void displaybowl(void);

void menu(void);

scorecard()

for(int n=0;n<12;n++)

runscored[n]={0};

oversplayed[n]={0};

maiden[n]={0};

runsgiven[n]={0};

wicketstaken[n]={0};

};

int main()

int jb=0;

scorecard s1;

int kb;

s1 menu();
do

Cout<<”Enter the option”<<endl;

Cout<<”(1) Diplay batting score”<<endl<<”(2) Display bowling score”<<endl<<”(3) Update batting


score”<<endl;

Cout<<”Update Bowling score”<<endl;

Cin>>kb;

switch(kb)

Case1:s1.displaybat();

break;

Case2:s1.displabowl();

break;

Case3:s1.upadatebatsman();

break;

Case4:s1.upadatebowler();

break;

default.cout<<”Wrong choice”;

While(jb<1);

void scorecard :: updatebowler(void)

{char bowlname[20];

int str, k, option overnumbers, maidenumb,upturn,upwicket;

cout<<”Enter Bowler name:”;

cin.getline(bowlername[k],bowlname);
if (str==0)

cout<<”Menu for bowler information update”<<endl;

cout<<”(1)Update Number of overs”,,endl<<”(2)Update maiden overs”<<endl<<”(3)Update runs


given”<<endl;

cout<<”(4)Update wickets taken”<<endl;

cin>>option;

switch(option)

case 1 :{cout<<”Enter Numbers of overs to be updated:”;

cin>>overnumbers;

cout<<endl;

overesplayed[k]+=overnumbers;

break;

case 2 :{cout<<”Enter the number of madian overs to be updated:”;

cin>>maidenumb;

cout<<endl;

maiden[k]+=maidenumb;

break;

case 3 :{cout<<”Enter the number of runs to be added: “;

cin>>uprun

cout<<endl;

runsgiven[k]+=uprun;

}
break;

case 4 :{cout<<”Enter number of wickets to be updated: ”;

cin>>upwicket;

cout<<endl;

wicketstaken[k]+=upwicket;

break;

default;cout<<”wroung choice”;

break;

if(str!=0)

cout<<”You entered wrong player.”<<endl;

void scorecard :: updatebatsman(void)

{char batsmen[20]

int str.k;

void scorecard::updatebatsman(void)
{char batsmaname[20];

int str,k;

cout<<"Enter Batsman name:";

cin.getline(batsmaname,20);

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

{str= strcmp(batname[k],batsmaname);

if (str== 0)

cout<<"enter runs scored:";

cin>>runscored[k];

cout<<endl<<"enter weather out or not out:";

cin>>situation[k];

cout<<endl<<"enter mode(if batsman out) by which batsman was out:";

cin>>mode[k];

break;

if (str!=0)

cout <<"You entered wrong player."<<endl;

}
void scorecard::displaybat(void)

cout << "Batsman name"<<'t'<<"Runs scored"<<'t'<<"situation"<<'t'<<"mode"<<endl;

for(int j=0;j++;j<12)

cout<<batname[j]<<'t'<<runscored[j]<<'t'<<situation[j]<<'t'<<mode[j]<<endl;

void scorecard::displaybowl(void)

cout << "Bowler name"<<'t'<<"overs played"<<'t'<<"maiden overs"<<'t'<<"wicket taken"<<'t'<<"Runs


given"<<endl;

cout<<endl;

for(int j=0;j++;j<12)

cout<<bowlername[j]<<'t'<<oversplayed[j]<<'t'<<maiden[j]<<'t'<<wicketstaken[j]<<'t'<<runsgiven[j]<<e
ndl;

void scorecard::menu(void)

cout<<"Enter the name of players of batting team"<<endl;

for (int k=0;k<11;k++)

{
cout <<"Enter name of player "<<k+1<<":";

cin>>batname[k];

cout <<"Enter the name of players of bowling team"<<endl;

for (int n=0;n<11;n++)

cout <<"Enter name of player "<<n+1<<":";

cin>>bowlername[n];

OUTPUT:

Enter the name of player=omkar

Enter the name of bowling team=ashish

Enter the name of palyer=Tejas

Enter the name of batting team=Manas

Runs of player=55

Runs of player=80

End date: Faculty Signature


Start date: Practical no:

18. Create a C++ class mydate with three members dd,mm,yy. Write a menu driven

Program with the following options.

-Increment date by 1 day. -Subtract 2 days from date.

(Use function overloading ).

SOURCE CODE:

#include<isostream.h>

#include<conio.h>

class mydate

private:int date:

char month;

double year;

public:

void getdata(int i)

date=i;

cout<<”Enter the date=”;

cin>>I;

void get date(char m)

Month=m;

cout<<”Enter the month=”;

cin>>m;

}
Void getdata(double y);

Year=y;

cout<<:Enter the year=”);

cin>>y;

void display(int i)

cout<<”data”<<I;

void display(char m)

cout<<”month /”<<m;

void display(double y)

Cout<<”year”<<y;

void main()

clrscr()

mydata m1;

m1.getdata(int i);

m1.getdata(char m);
m1.getdata(double y);

m1,display(int i);

m1.disaplay(int m);

m1.diplay (double y);

OUTPUT:

Enter the date=15

Enter the month=J

Enter the year=2019

date\15 month \J\2019

End date: Faculty Signature


Start date: Practical no:

19. Create two classes dist1(meters, centimeters) and dist2(feet, inches).

Accept two distances from the user, one in meter and centimeter and other in

feet and inches. Find the sum and differences of the two distances. Display

the result in both, meters and centimeters as well as feet and inches

(using friend function).

SOURCE CODE:

#include<iostream.h>

using namespace std;

//forward declaration

class B;

class A;

private:

int numA;

public:

A(): numA(12){}

//friend function declaration

friend int add(A,B);

};

//function add()is the friend of classes A and B

//that accesses the number variables numA and numb

Int add(A objectA,B object)

return(objectA.numA+objectB,numb);

}
Int main()

A objectA;

B object;

cout<<”Sum:”<<add(objectA,object);

return 0;

OUTPUT:

Sum:13

End date: Faculty Signature


Start date: Practical no:

20. Create a base class called Shape. Use this class to store two double values that could be

used to compute the area of figures. Derive three classes called as triangle, rectangle and

circle from the base Shape.

Add to the base class a member function get_data() to initialize base class data

members and another member function display_area() to compute and display the area of

figures. Make display_area() as a virtual function and redefine this function in the derived

classes to suit their requirements.

Using these four classes, design a program that will accept, dimensions of a triangle

and rectangle and radius of circle, and display the area.The two values given as input will

be treated as lengths of two sides in the case of rectangles and as base and height in the

case of triangles and used as follows :

Area of rectangle = x * y

Area of triangle = ½ * x * y

[In case of circle, get_data() will take only one argument i.e radius so make the second

argument as default argument with the value set to zero.]

SOURCE CODE:

#include<iostream.h>

#include<conio.h>

void main()

class shape

protected:

float width,height;

public:
void set_data(float a,float b)

width=0;

height=b;

};

class rectangle:public shape

public:

float area()

Return(width*height);

};

class traiangle:public shape

public:

float area()

{
return(width*height/2);

};

int main()

rectangle rect;

triangle tri;
rect.set_data(5,3);

tri.set_data(2,5)

cout<<”Area of rectangle is:”<<rect.area();

cout<<”\n Area of triangle is:”<<tri.area();

return 0;

OUTPUT:

Enter the width and height=15

12

Area of rectangle=54

Area of triangle=13

End date: Faculty Signature


Start date: Practical no:

21. Write a C++ program using multilevel inheritance concept which will display student

information ( Roll number ,marks obtain in two subject, total marks) use following

information

• Class student to get and put roll number, class test to get and put marks of two

subject & test will inherit class student

• Class Result to compute and display total marks

SOURCE CODE:

#include<iostream.h>

#include<conio.h>

class student

int roll no;

char name[20];

public:

void get()

cout<<”Enter your roll no=”;

cin>>roll no;

cout<<”Enter marks for first sub=”;

cin>>first sub;

cout<<”Enter marks fir second student=”;

cin>>second student;

T=f+s

}
void show()

cout<<”\n your roll no”>>roll no;

cout<<\n your marks of first sub”<<first sub;

cout<<\n your marks for second sub”<<second sub;

cout<<\n total marks”<<T;

};

int main()

student s1;

s1.get()

s1.show();

return 0;

OUTPUT:

Enter the roll no=12

Your marks of first sub=50

Your marks of second sub=50

Total marks=100

End date: Faculty Signature


Start date: Practical no:

22. C ++ program to demonstrate runtime polymorphism and display information of book

(Title, price, number of pages) and Tape (Title, price, time). use following information

• Class media with parameter to initialize media information title and price & virtual

function display

• Class Book will inherit media & it will contain data member number of page and display

function

Class tape will inherit class media & it will contain data member time and display

function

SOURCE CODE :

#include<iostream.h>

class media

protected:

int price=100,title=A,number of pages=50;

public:

media(int price1=100;title1=A;number of pages1=50)

Price=price1;

title=title1;

number of pages=number of pages1;

virtual void display()

cout<<price;
cout<<title;

cout<<number of pages;

class book:public media

int number of pages,price,title;

void get data

cin>>number of pages;

cin>>price;

cin>>title;

void display()

cout<<price<<price1;

cout<<title<<title1;

cout<<number of pages<<number of pages1;

class tape:public media

int time;

void accept(int time)

{
cin>>time;

void display()

cout<<title;

cout<<price;

cout<<title;

cout<<number of pages;

void main()

book b1=new book(100,”Avishkar”,5);

b1.getdata(8);

b1.display();

type t1=new type();

t1.accept(30 min);

t1.display();

getch();

}
OUTPUT:

number of page=15

price=100

title=A

number of pages1=15

price1=100

title1=50

End date: Faculty Signature

You might also like