Problem 88787
Problem 88787
#include<iostream>
using namespace std;
int main()
{
cout<<"Hello World"<<endl;
return 0;
}
int main()
float a,b;
cin>>a>>b;
cout<<(a*b);
return 0;
int main()
char a;
cin>>a;
cout<<int(a);
return 0;}
Problem: 1.6: C++ Program to Find Quotient and Remainder of Two Integers Entered by User
#include<iostream>
int main()
int a,b;
cin>>a>>b;
cout<<a/b<<endl;
cout<<(a%b);
return 0;
1
Problem: 1.7: C++ Program to Swap Two Numbers
#include<iostream>
using namespace std;
int main()
{
int a,b;
cout<<"please enter any two numbers: ";
cin>>a>>b;
a=(a+b);
b=(a-b);
a=(a-b);
cout<<a<<endl;
cout<<b; return 0;}
2
Problem: 1.9: C++ Program to Check Vowel or Consonant
#include <iostream>
int main()
char a;
cin>>a;
a=tolower(a);
else
return 0;
Problem: 1.10: C++ Program to Find the Largest Number Among Three Numbers
#include <iostream>
int main()
int num1,num2,num3;
cin>>num1>>num2>>num3;
else
return 0;
3
}
#include<math.h>
#include<conio.h>
int main()
float a,b,c,d,x1,x2;
cin>>a>>b>>c;
else
d=(b*b)-(4*a*c);
if(d>=0)
x1=(-b+sqrt(d))/(2*a);
x2=(-b-sqrt(d))/(2*a);
cout<<"x1 : "<<x1<<"\n";
cout<<"x2 : "<<x2<<"\n";
else
}}
getch();
}
4
Problem: 2.2: C++ Program to Check Whether a Number is Positive or Negative
#include<bits/stdc++.h>
int main()
float num;
cin>>num;
if(num>=0)
cout<<"Positive";
else
cout<<"Negetive";
getch();
Problem: 2.3: C++ Program to input a number. If the number is even, print its square otherwise print its cube.
#include<bits/stdc++.h>
#include<math.h>
int main(){
int num;
cin>>num;
if(num%2==0)
cout<<"Even"<<endl;
else
cout<<"Odd"<<endl;
5
cout<<"cube of the number is: "<<num*num*num;
getch();
Problem: 2.4: C++ Program to input marks in three subjects of a student and calculate the
division
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main()
{
int i,mark;
cout<<"enter the marks of a student: ""\n";
for(i=0; i<3; i++)
{
cout<<"subject "<<i+1<<": ";
cin>>mark;
if(mark>=60)
cout<<"Division: First""\n";
else if(mark<=59 && mark>=50)
cout<<"Division : Second""\n";
else if(mark<=49 && mark>=40)
cout<<"Division: Third""\n";
else
cout<<"Division: Fail""\n";
}
getch();
}
6
Problem: 2.5: C++ Program to check that a given year is a leap year or not. If not then calculate
the nearest leap year.
#include <bits/stdc++.h>
while (!LeapYear(pastYear))
pastYear--;
while (!LeapYear(futureYear))
futureYear++;
{return pastYear;}
else
return futureYear;
int main()
int year;
7
int nearestLeapYear = findNearestLeapYear(year);
cout << "The nearest leap year to " << year << " is " << nearestLeapYear << endl;
return 0;}
Problem: 2.6: C++ Program to input a character and check that it’s a small letter, capital letter,
a digit or a special symbol.
#include<bits/stdc++.h>
#include<math.h>
#include<conio.h>
using namespace std;
int main()
{
char ch;
int i;
for(i=0; i<4; i++)
{
cout<<"enter any character: ";
cin>>ch;
if(ch>='a' && ch<='z')
cout<<"Small letter""\n";
else if(ch>='A' && ch<='Z')
cout<<"Capital letter""\n";
else if(ch>='0' && ch<='9')
cout<<"A digit""\n";
else
cout<<"A special symbol""\n";
}
getch();
8
}
Problem: 2.7: Write a C++ program to find out the sum of series 1 + 2 + …. + n.
#include<bits/stdc++.h>
#include<math.h>
#include<conio.h>
using namespace std;
int main()
{
int i,num,sum=0;
cout<<"enter any number: ";
cin>>num;
for(i=0;i<=num;i++)
{
sum=sum+i;
cout<<i<<" ";
}
cout<<"\n""sum of the series: "<<sum;
getch();
}
9
Problem: 2.8: Write a C++ program to find out the sum of series 1^3 + 2^3 + …. + n^3.
#include<bits/stdc++.h>
#include<math.h>
#include<conio.h>
using namespace std;
int main()
{
int i,num,sum=0;
cout<<"enter any number: ";
cin>>num;
for(i=0;i<=num;i++)
{
sum=sum+(i*i*i);
cout<<i*i*i<<" ";
}
cout<<"\n""sum of the series: "<<sum<<endl;
getch();
}
10
Problem: 2.9: Write a C++ Program to Reverse a Number.
#include<bits/stdc++.h>
#include<math.h>
#include<conio.h>
using namespace std;
int revnum(int num)
{
int rev = 0;
while (num != 0)
{
int digit = num % 10;
rev = rev * 10 + digit;
num /= 10;
}
return rev;
}
int main()
{
int num;
cout << "Enter a number: ";
cin >> num;
int reverseNum = revnum(num);
cout << "Reversed number: " << reverseNum << endl;
getch();
11
}
Problem: 2.11: Write a C++ program to input any number from user and displays the total of its
digits
#include<bits/stdc++.h>
#include<conio.h>
using namespace std;
int main()
{
int num,remainder,sum=0,OriginalNumber;
cout<<"enter any number: ";
cin>>num;
OriginalNumber=num;
while(num!=0)
{
remainder=num%10;
sum=sum+remainder;
num=num/10;
}
cout<<"The sum of the total digit "<<OriginalNumber<<" is: "<<sum<<endl;
getch();
}
13
Problem: 3.1: Write a C++ program that calculates and displays the area of a circle. The program should
prompt the user to enter the radius of the circle and then output the calculated area. Utilize a function area to
perform the area calculation, and include the necessary header files and constants
#include<bits/stdc++.h>
#include<conio.h>
#include<math.h>
using namespace std;
int area(int length, int width)
{
return length*width;
}
int main()
{
int length,width;
cout<<"enter length and width of a rectangle: ";
cin>>length>>width;
int rectangle=area(length,width);
cout<<"the area of a rectangle is: "<<rectangle;
getch();
}
14
Problem: 3.2: Write a C++ program that calculates and displays the area of a rectangle. The program should
prompt the user to enter the length and width of the rectangle and then output the calculated area. Use the
function calculateArea to perform the area calculation.
#include<bits/stdc++.h>
#include<conio.h>
#include<math.h>
using namespace std;
float area(int r)
{
return 3.1416*r*r;
}
int main()
{
int radius;
cout<<"enter the radius of a circle: ";
cin>>radius;
float circle=area(radius);
cout<<"the area of a circle is: "<<circle;
getch();
}
Problem: 3.3 Write a C++ program that take two functions that gets three integers and returns
maximum and minimum.
#include<bits/stdc++.h>
#include<conio.h>
#include<math.h>
using namespace std;
int midNum(int num1,int num2,int num3)
15
{
if(num2>=num1 && num3<=num1)
return num1;
else if(num1>=num2 && num3<=num2)
return num2;
else
return num3;
}
int main()
{
int num1,num2,num3;
cout<<"enter the three numbers: ";
cin>>num1>>num2>>num3;
int midium=midNum(num1,num2,num3);
cout<<"the midium number among three number is: "<<midium;
getch();
}
Problem: 3.4: Write a function that gets any
positive number and returns its factorial.
#include<bits/stdc++.h>
#include<conio.h>
#include<math.h>
using namespace std;
int factorial(int n)
{
if(n<=0)
return 1;
16
else
return n*factorial(n-1);
}
int main()
{
int num;
cout<<"enter any positive number: ";
cin>>num;
int fact=factorial(num);
cout<<"the factorial of "<<num<<" is: "<<fact;
getch();
}
Problem 3.5: Write a function that gets any positive number and returns sum of its digit
#include<bits/stdc++.h>
#include<conio.h>
#include<math.h>
using namespace std;
int sumDigits(int num)
{
int remainder,sum=0;
while(num>0)
{
remainder=num%10;
sum=sum+remainder;
num=num/10;
17
}
return sum;
}
int main()
{
int num;
cout<<"enter any positive number: ";
cin>>num;
if(num<0)
cout<<"Error! please
enter a positive number";
else
{
int sum=sumDigits(num);
cout<<"the sum of "<<num<<" is: "<<sum;
}
getch();
}
Problem: 3.6: Write a function that gets any positive number and returns digital root.
#include<bits/stdc++.h>
#include<conio.h>
#include<math.h>
using namespace std;
int digital(int num)
{
int sum=0;
if(num<10)
18
return num;
else
{
while(num>0)
{
sum=sum+(num%10);
num=num/10;
}
return digital(sum);
}
}
int main()
{
int num;
cout<<"enter any positive number: ";
cin>>num;
int root=digital(num);
if(num<0)
cout<<"error! please enter any positive number: ";
else
cout<<"the digital root of "<<num<<" is: "<<root;
getch();
}
Problem: 3.7: Write a C++ program that take four functions that gets two integer and returns its
sum ,subtraction, multiplication, division.
#include<bits/stdc++.h>
#include<conio.h>
19
#include<math.h>
using namespace std;
int sum(int num1,int num2)
{
return num1+num2;
}
int sub(int num1,int num2)
{
return num1-num2;
}
int multiple(int num1,int num2)
{
return num1*num2;
}
float divide(int num1,int num2)
{
return num1/num2;
}
int main()
{
int num1,num2;
cout<<"enter any two numbers: ";
cin>>num1>>num2;
int sumNumber,subNumber,multiplication;
float divideNumber;
sumNumber=sum(num1,num2);
subNumber=sub(num1,num2);
20
multiplication=multiple(num1,num2);
divideNumber=divide(num1,num2);
cout<<"the sum two number is: "<<sumNumber<<"\n";
cout<<"the sub two number is: "<<subNumber<<endl;
cout<<"the multiplication of two number is: "<<multiplication<<endl;
cout<<"the dividation of two number is: "<<divideNumber<<endl;
getch();
}
Problem: 3.8:
#include<bits/stdc++.h>
#include<conio.h>
#include<math.h>
using namespace std;
int maximum(int num1,int num2,int num3)
{
if(num1>=num2 && num1>=num3)
return num1;
else if(num2>=num1 && num2>=num3)
return num2;
else
return num3;
}
int minimum(int num1,int num2,int num3)
{
if(num1<=num2 && num1<=num3)
return num1;
else if(num2<=num1 && num2<=num3)
21
return num2;
else
return num3;
}
int main()
{
int num1,num2,num3;
cout<<"enter any three numbers: ";
cin>>num1>>num2>>num3;
int maxNum,minNum;
maxNum=maximum(num1,num2,num3);
minNum=minimum(num1,num2,num3);
cout<<"the maximum number is: "<<maxNum<<"\n";
cout<<"the minimum number is: "<<minNum<<endl;
getch();
}
Problem: 3.9: Write a C++ program using user-define function that calculates and displays the
averages of sets of numbers.
#include<bits/stdc++.h>
#include<conio.h>
#include<math.h>
using namespace std;
void average(int num1,int num2)
{
cout<<"enter any two numbers: ";
22
cin>>num1>>num2;
int avg=(num1+num2)/2;
cout<<"average of two numbers: "<<avg<<endl<<endl;
}
void average(float num1,float num2,float num3)
{
cout<<"enter any three numbers: ";
cin>>num1>>num2>>num3;
float avg=(num1+num2+num3)/3;
cout<<"average of three numbers: "<<avg<<endl<<endl;
}
int main()
{
double num1,num2,num3,num4;
average(num1,num2);
average(num1,num2,num3);
average(num1,num2,num3,num4);
getch();
23
}
Problem 4.1:
#include<iostream>
#include<conio.h>
using namespace std;
class person
{
string
name,country;
int age;
public:
person()
{
name="Md.Mohaimin Mahin";
country = "Bangladesh";
age=23;
cout<<"constructor created"<<endl;
}
~person()
{
cout<<"Person's name is: "<<name<<endl;
cout<<"His Country name: "<<country<<endl;
cout<<"His age: "<<age<<endl;
24
cout<<"destruction done"<<endl;
}
};
int main()
{
person one;
return 0;
}
Problem 4.2:
#include<iostream>
#include<conio.h>
using namespace std;
class Box
{
float height,length,width;
public:
Box()
{
height=4;
length=5;
width=2;
cout<<"constructor created"<<endl;
}
float print_volume()
{
25
return height*length*width;
}
~Box()
{
cout<<"The height,length,width of the Box: 4,5,2"<<endl;
cout<<"The volume of the Box: "<<print_volume()<<endl;
cout<<"destruction done"<<endl;
}
};
int main()
{
Box vol;
return 0;
}
Problem 4.3:
#include<iostream>
#include<conio.h>
using namespace std;
class registerer
{
string name,address,blood_group,date_of_birth;
int idnumber;
public:
26
void contain(string n,string a,string b,string d,int i)
{
name=n;
address=a;
blood_group=b;
date_of_birth=d;
idnumber=i;
}
void display()
{
cout<<"Name of the person: "<<name<<endl;
cout<<"Address of the person: "<<address<<endl;
cout<<"Blood group of the person: "<<blood_group<<endl;
cout<<"Date of birth of the person: "<<date_of_birth<<endl;
cout<<"ID of the person: "<<idnumber<<endl;
}
};
int main()
{
registerer person;
string n,a,b,d;
int i;
cout<<"Enter name: "<<endl;
getline(cin,n);
cout<<"Enter address: "<<endl;
getline(cin,a);
27
cout<<"Enter blood group: "<<endl;
getline(cin,b);
cout<<"Enter date of birth: "<<endl;
getline(cin,d);
cout<<"Enter ID: "<<endl;
cin>>i;
cout<<endl<<endl;
cin.ignore();
person.contain(n,a ,b,d,i);
person.display();
return 0;
}
Problem 5.1:
#include<iostream>
#include<conio.h>
class calculator
{ int a=24,b=4;
int sum()
return a+b;
int sub()
return a-b;
int multiplication()
28
{
return a*b;
float division()
return a/b;
public:
void show()
};
int main()
calculator cal;
cal.show();
return 0;
Problem 5.2:
#include<iostream>
#include<conio.h>
int prime(int n)
int i,f=1;
29
if(n%i==0)
f=0;
return f;
int main()
int n,m,primeNum;
cin>>n>>m;
primeNum=prime(i);
if(primeNum==1)
cout<<i<<" ";
}}
return 0;
Problem 5.3:
#include<iostream>
#include<conio.h>
int fibo(int n)
if(n==0 || n==1)
return 1;
else
30
return (fibo(n-1)+fibo(n-2));
int main()
int n,fibonacci;
cin>>n;
fibonacci=fibo(i);
cout<<fibonacci<<" ";
return 0;
Problem 5.4:
#include<iostream>
#include<conio.h>
class circle
int radius;
public:
void comput_area(int r)
radius=r;
float area=3.1416*radius*radius;
};
31
int main()
circle cir;
int r;
cin>>r;
cout<<endl;
cir.comput_area(r);
return 0;
Problem 5.5:
#include<iostream>
#include<conio.h>
class summation
int number1,number2;
public:
number1=n1;
number2=n2;
int add=number1+number2;
};
int main()
summation add;
int n1,n2;
32
cout<<"enter the two numbers: ";
cin>>n1>>n2;
cout<<endl;
add.sum(n1,n2);
return 0;
Problem 5.6:
#include<iostream>
#include<conio.h>
class rectangle
int length,width;
public:
void set1()
length=4;
width=6;
int get_area()
return length*width;
};
int main()
rectangle box;
box.set1();
float area=box.get_area();
33
return 0;
Problem 5.7:
#include<iostream>
#include<conio.h>
using namespace std;
class calculator
{
int a=24,b=4;
int sum()
{
return a+b;
}
int sub()
{
return a-b;
}
int
multiplication()
{
return a*b;
}
float division()
{
return a/b;
}
34
public:
void show()
{
cout<<"sum of 24 & 4 is: "<<sum()<<endl;
cout<<"sub of 24 & 4 is: "<<sub()<<endl;
cout<<"multiplication of 24 & 4 is: "<<multiplication()<<endl;
cout<<"division of 24 & 4 is: "<<division()<<endl;
}
};
int main()
{
calculator cal;
cal.show();
return 0;
}
Problem 6.1:
#include<iostream>
#include<conio.h>
using namespace std;
class card
{
string title,author;
int num_books;
public:
void store()
35
{
title="A Brief Histroy of Time";
author="Stephen Howkings";
num_books=50;
}
void display()
{
cout<<"Name of the book: "<<title<<endl;
cout<<"Name of the author: "<<author<<endl;
cout<<"number of books: "<<num_books<<endl;
}
};
int main()
{
card one;
one.store();
one.display();
return 0;
}
Problem 6.2:
#include<iostream>
#include<conio.h>
using namespace std;
class prime
{
int num;
36
public:
void get_input()
{
int n;
cout<<"enter any positive number: ";
cin>>n;
num=n;
}
int calculate()
{
int i,f=1;
for(i=2;i<num/2;i++)
{
if(num%i==0)
return 0;
}
return f;
}
void display()
{
int primenum=calculate();
if(primenum==1)
cout<<"Given number is prime number"<<endl;
else
cout<<"Given number is not prime number"<<endl;
}
37
};
int main()
{
prime number;
number.get_input();
number.display();
return 0;
}
Problem 6.3:
#include<iostream>
#include<conio.h>
using namespace std;
class student
{
string name;
int ID;
float cgpa;
public:
student(string n,int i,float c)
{ name=n;
ID=i;
cgpa=c;
}
friend void studentinfo(student info);
};
void studentinfo(student info)
38
{
cout<<"the information of the student is given below"<<endl<<endl;
cout<<"name of the student: "<<info.name<<endl;
cout<<"Student's ID: "<<info.ID<<endl;
cout<<"Student's CGPA: "<<info.cgpa<<endl;
}
int main()
{
string n;
int i;
float c;
cout<<"enter students name: ";
getline(cin,n);
cout<<"enter students ID: ";
cin>>i;
cout<<"enter students CGPA: ";
cin>>c;
cout<<endl;
student info(n,i,c);
studentinfo(info);
}
Problem 6.4:
#include<iostream>
#include<conio.h>
using namespace std;
class registerer
39
{
string name,address,blood_group,date_of_birth;
int idnumber;
public:
void contain(string n,string a,string b,string d,int i)
{
name=n;
address=a;
blood_group=b;
date_of_birth=d;
idnumber=i;
}
void display()
{
cout<<"Name of the person: "<<name<<endl;
cout<<"Address of the person: "<<address<<endl;
cout<<"Blood group of the person: "<<blood_group<<endl;
cout<<"Date of birth of the person: "<<date_of_birth<<endl;
cout<<"ID of the person: "<<idnumber<<endl;
}
};
int main()
{
registerer person;
string n,a,b,d;
40
int i;
cout<<"Enter name: "<<endl;
getline(cin,n);
cout<<"Enter address: "<<endl;
getline(cin,a);
cout<<"Enter blood group: "<<endl;
getline(cin,b);
cout<<"Enter date of birth: "<<endl;
getline(cin,d);
cout<<"Enter ID: "<<endl;
cin>>i;
cout<<endl<<endl;
cin.ignore();
person.contain(n,a,b,d,i);
person.display();
return 0;
}
41