Professional Documents
Culture Documents
INDEX
S. No. Activity Name Page No. Remark
2. WAP in C++ to find the greatest no. between three number. 2-3
5. WAP in C++ to find the given year is leap or not using logical operator. 6-7
10. WAP in C++ to enter and display 10 Element in one dimensional 16-17
array.
11. WAP in C++ to find the sum of 2 Matrix. 18-19
13. WAP in C++ to perform all arithmetic operation using switch 23-25
statement.
14. WAP in C++ to enter and display a student record using structure 26-27
required field are: student id student name, student class and
percentage.
15. WAP in C++ to insert and display a book record using union required 28-29
field are: book id, book name, author name and prize.
16. WAP in C++ to find factorial of any given number using recursion. 30
#include<iostream>
int main()
int num;
cin>>num;
if(num%2==0)
else
cout<<endl;
return 0;
Output:--
PS C :\ Users\HP\Desktop\c++> g++ .\even_odd.cpp
PS C:\Users\HP\Desktop\c++ -\a.exe
Enter a Number : 5
It is an Odd Number .
PS C : \Users\HP\Desktop\c++
2. WAP in C++ to find the greatest no. between three number.
#include<iostream>
int main()
cin>>numOne>>numTwo>>numThree;
if(numOne>numTwo)
if(numTwo>numThree)
larg = numOne;
else
if(numThree>numOne)
larg = numThree;
else
larg = numOne;
else
if(numTwo>numThree)
larg = numTwo;
else
larg = numThree;
} Pg:2
cout<<"\nLargest Number = "<<larg;
cout<<endl;
return 0;
Output:--
PS C : \Users\HP\Desktop\c++> g++ .\larg_three_no.cpp
PS C : \User\HP\Desktop\c++> .\a.exe
Largest Number = 9
PS C:\Users\HP\Desktop\c++>
int main()
cin>>len;
cin>>bre;
area = len*bre;
cout<<"\nArea = "<<area;
cout<<endl;
return 0;
Output:--
Area = 24
PC C: \Users\HP\Desktop\c++>
int main()
cout << "\n\n Swap two numbers without using third variable:\n";
num2=num2+num1;
num1=num2-num1;
num2=num2-num1;
cout << " After swapping the 1st number is : "<< num1 <<"\n" ;
cout << " After swapping the 2nd number is : "<< num2 <<"\n\n" ;
Output:--
---------------------------------------------------------------------------
PS C: \Users\HP\Desktop\c++>
5. WAP in C++ to find the given year is leap or not using logical operator.
#include<iostream>
using namespace std;
int main()
int y;
cout<<"Enter year : ";
cin>>y;
if(y%4==0)
{
if(y%100==0)
{
if(y%400==0)
cout<<"leap year";
else
cout<<"not leap year";
}
else
cout<<"leap year";
}
else
cout<<"not leap year";
return 0;
Output:--
PS C: \Users\HP\Desktop\c++> g++ .\leap-year .cpp
PS C: \Users\HP\Desktop\c++ . \a.exe
PS C: \Users\HP\Desktop\c++>
using namespace std;
int main()
{
int n, i, m=0, flag=0;
cout << "Enter the Number to check Prime: ";
cin >> n;
m=n/2;
for(i = 2; i <= m; i++)
{
if(n % i == 0)
{
cout<<"Number is not Prime."<<endl;
flag=1;
break;
}
}
if (flag==0)
cout << "Number is Prime."<<endl;
return 0;
}
Pg:8
Output:--
PS c: \User\HP\Desktop\c++>
using namespace std;
int main()
{
int n,r,sum=0,temp;
cout<<"Enter the Number= ";
cin>>n;
temp=n;
while(n>0)
{
r=n%10;
sum=sum+(r*r*r);
n=n/10;
}
if(temp==sum)
cout<<"Armstrong Number."<<endl;
else
cout<<"Not Armstrong Number."<<endl;
return 0;
}
Pg:10
Output:--
PS C:\User\HP\Desktop\c++>
using namespace std;
int main()
int n, num, digit, rev = 0;
cout << "Enter a positive number: ";
cin >> num;
n = num;
do
{
digit = num % 10;
rev = (rev * 10) + digit;
num = num / 10;
} while (num != 0);
cout << " The reverse of the number is: " << rev << endl;
if (n == rev)
cout << " The number is a palindrome.";
else
cout << " The number is not a palindrome.";
Pg:12
return 0;
}
Output:--
PS C : \Users\HP\Desktop\c++> g++ .\ palindrome.cpp
PS C :\Users\HP\desktop\c++> .\a.exe
PS C:\Users\HP\Dsktop\c++
int main() {
int n, t1 = 0, t2 = 1, nextTerm = 0;
cout << "Enter the number of terms: ";
cin >> n;
cout << "Fibonacci Series: ";
for (int i = 1; i <= n; ++i) {
// Prints the first two terms.
if(i == 1) {
cout << t1 << ", ";
continue;
}
if(i == 2) {
cout << t2 << ", ";
continue;
}
nextTerm = t1 + t2;
t1 = t2;
t2 = nextTerm;
Pg:14
cout << nextTerm << ", ";
}
return 0;
Output:--
PS C:\Users\HP\Desktop\c++> . \a.exe
Fibonacci Series: 0, 1, 1, 2, 3, 5,
PS C:\ Users\HP\Desktop\c
Pg:15
10. WAP in C++ to enter and display 10 Element in one dimensional array.
#include<iostream>
int main()
cin>>tot;
cin>>arr[i];
cout<<"arr["<<i<<"]"<<"\t\t\t"<<arr[i]<<endl;
cout<<endl;
return 0;
Output:--
PS C: \ Users\HP\Desktop\c++> . \a.exe
Enter 10 Numbers: 1 2 3 4 5 6 7 8 9
Array with Index Its Value
arr[0] 1
arr[1] 2
arr[2] 5
arr[3] 4
arr[4] 5
arr[5] 4
arr[6] 6
arr[7] 4
arr[8] 6
arr[9] 9
PS C:\User\HP\Desktop\c++>
int main()
{
{
cout<<" ";
cin>>m1[i][j];
}
}
{
{
cout<<" ";
cin>>m2[i][j];
}
}
{
{
m3[i][j]=m1[i][j]+m2[i][j];
}
}
{
cout<<" ";
for(j=0; j<3; j++)
{
cout<<m3[i][j]<<" ";
}
cout<<"\n";
}
return 0;
Output:--
PS C: \Users\HP\Desktop\c++ .\a.exe
26 5
3 2 1
2 5 8
1 5 8
2 6 9
3 10 12
5 7 9
4 11 17
int main()
{
int a[10][10],b[10][10],mul[10][10],r,c,i,j,k;
cin>>c;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cin>>a[i][j];
}
}
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cin>>b[i][j];
}
}
for(i=0;i<r;i++)
{ Pg:20
for(j=0;j<c;j++)
{
mul[i][j]=0;
for(k=0;k<c;k++)
{
mul[i][j]+=a[i][k]*b[k][j];
}
}
}
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cout<<mul[i][j]<<" ";
}
cout<<"\n";
return 0;
}
Output:--
PS C: \Users\HP\Desktop\c++> g++ .|multi.cpp
PS C: \Users\HP\Desktop\c++> .\a.exe
s
enter the second matrix element=
13. WAP in C++ to perform all arithmetic operation using switch statement.
#include<iostream>
int main() {
int x, y, res;
int ch;
cout << "Enter 1 For Addition :";
switch (ch) {
case 1:
{
res = x + y;
break;
}
case 2: Pg:23
{
res = x - y;
break;
}
case 3:
{
res = x * y;
break;
}
case 4:
{
res = x / y;
break;
} Pg:24
case 5:
{
res = x % y;
break;
}
}
return 0;
Output:--
PS C: \Users\HP\Desktop\c++> g++ .\all.arith.cpp
PS C: \Users\HP\Desktop\c++> .\a.exe
Result is : 30
PS C: \Users\HP\desktop\c++>
14. WAP in C++ to enter and display a student record using structure required field are:
student id student name, student class and percentage.
#include <iostream>
struct student
char name[50];
int roll;
float marks;
} s[10];
int main()
// storing information
{
s[i].roll = i+1;
cout << "For roll number" << s[i].roll << "," << endl;
}
// Displaying information
{
return 0;
Output:--
Enter name: Enter marks:
Displaying Information:
Roll number: 1
Marks: 0
Roll number : 2
Name:
Marks: 0
Roll number: 3
Name:
Marks: 0
Roll number: 4
Name:
Marks: 0
Roll number: 5
Name:
Marks: 0
PC c:\Users\HP\Desktop\c++>
Pg:27
15. WAP in C++ to insert and display a book record using union required field are: book id,
book name, author name and prize.
#include <iostream>
struct Book {
char name[100];
int price;
int ISBN;
};
int main() {
Book b;
cin.getline(b.name, 100);
return 0;
Pg:28
Output:--
PS C: \Users\HP\Desktop\c++> g++ .\book.cpp
PS C: \ Users\HP\Desktop\c++> .\a.exe
Biology
500
2586
Name : biology
Price : 500
PS C:\Users\HP\Desktop\c++
16. WAP in C++ to find factorial of any given number using recursion.
#include<iostream>
int main() {
int n;
cin >> n;
cout << "Factorial of " << n << " = " << factorial(n);
return 0;
int factorial(int n) {
if(n > 1)
else
return 1;
Output:--
PS C: \Users\HP\Desktop\c++> g++ .\recusion.cpp
PS C: \ Users\HP\Desktop\c++> .\a.exe
Factorial of 8 = 40320
PS C: \Users\HP\Desktop\c++>
Pg:30
class Cal {
public:
return a + b;
}
return a + b + c;
}
};
int main(void) {
Cal C; .
cout<<C.add(10, 20)<<endl;
return 0;
}
Output:--
PS C: \Users\HP\Desktop\c++> g++ .\function_over.cpp
PS C: \ Users\HP\Desktop\c++> .\a.exe
30
60
PS c: \Users\HP\Desktop\c++
Output:-
PS C: \Users\HP\Desktop\c++> g++ .\inheritance.cpp
PS C: \ Users\HP\Desktop\c++> .\a.exe
Salary: 75000
Bonus: 7500
PS c: \Users\HP\Desktop\c++>
class Room {
private:
double length;
double breadth;
public:
// 1. Constructor with no arguments
Room() {
length = 6.9;
breadth = 4.2;
}
Room(double l, double b) {
length = l;
breadth = b;
}
Room(double len) {
length = len;
breadth = 7.2;
}
double calculateArea() {
}
}; Pg:33
int main() {
cout << "\nWhen breadth is fixed to 7.2 and (8.2) is passed:" << endl;
return 0;
}
Output:--
PS C: \Users\HP\Desktop\c++> g++ .\construc.cpp
PS C: \ Users\HP\Desktop\c++> .\a.exe
PS c: \Users\HP\Desktop\c++>
#include <iostream>
class Distance {
private:
int meter;
// friend function
Distance() : meter(0) {}
};
int addFive(Distance d) {
d.meter += 5;
return d.meter;
int main() {
Distance D;
return 0;
Pg:35
Output:--
PS C: \Users\HP\Desktop\c++> g++ .\friend_function.cpp
PS C: \ Users\HP\Desktop\c++> .\a.exe
Distance: 8
PS c: \Users\HP\Desktop\c++>
Pg:36