0% found this document useful (0 votes)
14 views7 pages

Fyjc Cs1 Pract-1

The document contains a series of practical exercises in C++ programming, each with a specific aim and corresponding code examples. It covers various programming concepts such as input/output, control structures, functions, recursion, and operator overloading. Each practical includes sample output demonstrating the expected results of the code.

Uploaded by

8e28singh Tanvi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views7 pages

Fyjc Cs1 Pract-1

The document contains a series of practical exercises in C++ programming, each with a specific aim and corresponding code examples. It covers various programming concepts such as input/output, control structures, functions, recursion, and operator overloading. Each practical includes sample output demonstrating the expected results of the code.

Uploaded by

8e28singh Tanvi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Practical 1

Aim- Write simple C++ program.

Code-
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<”Welcome to C++”;
getch();
}

OUTPUT
Welcome to C++

Practical 2

Aim- Write a C++ program to find class according to % marks(using multiple path).
Code-
#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
int total;
cout<<”Enter total marks:”;
cin>>total;
if(total >100 && total <=0)
cout<<”Invalid”;
else if(total >=70 && total < 100)
cout<<”Distinction”;
else if(total >=60 && total < 70)
cout<<”First class”;
else if(total >=50 && total < 60)
cout<<”Second class”;
else
cout<<”Fail!”;
}
Output:
Enter total marks: 85
Distinction
Practical 3
Aim- Write a C++ program deciding the day of a week using switch case construct.
Code-
#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
int day;
cout<<”Enter number in the range of 1 to 7 to get corresponding day:”;
cin>>day;
switch(day)
{
case 1: cout<<”Today is Sunday”;
break;
case 2: cout<<”Today is Monday”;
break;
case 3: cout<<”Today is Tuesday”;
break;
case 4: cout<<”Today is Wednesday”;
break;
case 5: cout<<”Today is Thursday”;
break;
case 6: cout<<”Today is Friday”;
break;
case 7: cout<<”Today is Saturday”;
break;
default: cout<<”Not a valid day”;
break;
}
getch();
}
OUTPUT:
Enter the number in the range of 1 to 7 to get the corresponding day : 3
Today is Tuesday.
Practical 4
Aim- Write a C++ program to find addition of first 10 numbers using for loop.
Code-
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int total=0;
for(int i=1; i<11; i++)
{
total=total+i;
}
cout<<”Sum of first 10 numbers is :”<<total;
}
Output:
Sum of first 10 numbers is : 55

Practical 5
Aim- Write a C++ program to prints multiplication table for numbers 1 to 5(using for loop)
Code-
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void main()
{
for(int count1=1; count1<=5;count1++)
{
for(int count2=1; count2<=5;count2++)
cout<<setw(5)<<count1*count2;
cout<<endl;
}
getch();
}

OUTPUT:
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
Practical 6
Aim- Write a C++ program to display area of circle using function.
Code-
double area(double);
#include<iostream.h>
#include<conio.h>
void main()
{
double r,a;
cout<<”Enter radius”;
cin>>r;
a=area(r);
cout<<”area of circle is:”<<a;
}
double area(double r)
{
double a;
a=3.14*r*r;
return a;
}

OUTPUT:
Enter radius: 3
Area of circle is: 28.26

Practical 7
Aim- Write a C++ program to calculate factorial using recursion.
Code-
int factorial(int n);
#include<iostream.h>
#include<conio.h>
void main()
{
int n,f;
cout<<”Enter the number of which factorial is to be found:”;
cin>>n;
f=factorial(n);
cout<<”Factorial is:”<<f;
getch();
}
int factorial(int n)
{
int fact=1;
if(n==1)
return 1;
else
{
fact=factorial(n-1)*n;
return (fact);
}
}

OUTPUT:
Enter the no. of which factorial is to be found : 3
Factorial is : 6

Practical 8
Aim- Write a C++ program to display output of * using for loop.
Code-
#include<iostream.h>
#include<conio.h>
void main()
{
int i,r;
for(i=1;i<=4;i++)
{
for(r=1;r<=i;r++)
{
cout<<”*”;
}
cout<<endl;
}
getch();
}

OUTPUT:
*
**
***
****
Practical 9
Aim- Write a C++ program to demonstrate use of default arguments.
void add(int a, int b=0,int c=6);
#include<iostream.h>
#include<conio.h>
void main()
{
add(3);
add(3,5);
add(1,2,3);
getch();
}
void add(int a, int b, int c)
{
cout<<(a+b+c);
}

OUTPUT:
9 14 6

Practical 10

Aim- Write a C++ program to illustrate difference between local and global variable.

#include<iostream.h>
#include<conio.h>
int m=10;
void main()
{
int k=m;
int m=30;
cout<<”we are in inner block\n”;
cout<<”k=”<<k<<”\n”;
cout<<”local m=”<<m<<”\n”;
cout<<”global m=”<<::m<<”\n”;
getch();
}

OUTPUT:
We are in inner block
k=20
local m=30
global m=10
Practical 11
Aim- Write a C++ program to calculates the area of circle and rectangle using overloaded
function area.
double area(int);
int area(int, int);
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int r,l,b;
double areacircle, arearect;
cout<<”Enter length and breadth:”;
cin>>l>>b;
arearect=area(l,b);
cout<<”area of rectangle is:”<<arearect<<endl;
cout<<”Entre radius:”;
cin>>r;
areacircle=area(r);
cout<<”area of circle is:”<<areacircle;
getch();
}
double area(int r)
{
double area1;
const double pi=3.14;
area1=(pi*r*r);
return area1;
}
int area(int l, int b)
{
int area2=l*b;
Return area2;
}

OUTPUT:
Enter Length and breadth: 3 5
Area of rectangle is: 15
Enter radius: 3
Area of circle is : 28.26

You might also like