0% found this document useful (0 votes)
34 views42 pages

Haider

Uploaded by

mr.haider346
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)
34 views42 pages

Haider

Uploaded by

mr.haider346
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/ 42

Programming

Fundamentals

Name: Haider Sharif

Roll no. : Cosc-241131209

Class : BS-SE_(B)

Submitted to : Mam Samina

Naz.

EMERSON UNIVERSITY MULTAN


1

C++ Programs
Get Started :
Statement_1 : My First Program.
#include<iostream>
using namespace std;

int main()
{
cout << "Hello World!"
<< endl;
return 0;
}

Output:

Statement_2 : Use of input/output statements


#include<iostream>
using namespace std;

int main()
{
int num;
cout << "Enter a number :";
cin >> num;
cout << "The number is :"<<num;
return 0;
}
Output:

Conditional Statements:
Use of if-statement
Statement_3 : WAP to find the number is less then 10 or not?
#include<iostream>
using namespace std;

int main()
{
int num;
cout <<"Enter a
number :";
cin>>num;
if(num<10)
cout<<"The
number is less then
10";
return 0;
}Output :

Use of if- else


Statement
Statement_4 : WAP to find even & odd number

#include<iostream>
using namespace std;

int main()
{
int num;
cout <<"Enter a number :";
cin>>num;
if(num%2==0)
cout<<"The number is even";
else
cout<<"The number is odd"; 3
return 0;
}

Output:

Repetition Statements:
Use of for loop
Statement_5 : Print numbers using for loop
#include<iostream>
using namespace std;

int main()
{
int num, i;
cout <<"Enter a number :";
cin>>num;
for(i=0; i<=num; i++)
cout<<"result is :"<<i<<endl;
return 0;
}
Output:

Use of While loops


Statement_6 : WAP in while loop
#include<iostream>
using namespace std;

int main()
{
int num, i;
cout <<"Enter a number :";
cin>>num;
i=1;
while(i<=num)
{
cout<<"result is :"<<i<<endl;
i++;
}
return 0;
}
Output:
Dry run:

Statement_7 : WAP to find the number is Prime or Composite.


#include<iostream>
using namespace std;
int main()
{
int n,j,count=0;
cout<<"enter a number"<<endl;
cin>>n;
j==1;
while(j<=n)
{
if(n%j==0)
count++;
j++;
}
if(count==0)
cout<<n<<"PRIME"<<endl;
else
cout<<n<<"COMPOSITE"<<endl;
return 0;
}
Output:

Dry run:

Use of nested loops


Statement_8 : WAP of nested loops
#include<iostream>
using namespace std;

int main()
{
int num, i, j;
cout <<"Enter a number :";
cin>>num;
for(i=1; i<=num; i++)
{
for(j=1; j<=num; j++)
cout<<"Hello..!!"<<endl;
}
return 0;
}
Output:
Dry run:

Break Statement
Statement_9 : WAP to use break statement
#include<iostream>
using namespace std;

int main()
{
int num, i; 7
cout <<"Enter a number :";
cin>>num;
for(i=1; i<=num; i++)
{
if(i==5)
break;
cout<<i<<endl;
}
return 0;
}
Output:

Dry Run:

Continues Statement
Statement_10 : WAP to use continue statement
#include<iostream>
using namespace std;

int main()
{
int num, i;
cout <<"Enter a number :";
cin>>num;
for(i=1; i<=num; i++)
{
if(i==5)
continue;
cout<<i<<endl;
}
return 0;

} 8

Output:
Switch Statement :
Statement_11 : WAP to calculate grade in switch statement
#include<iostream>
using namespace std;
int main()
{
int page;
cout<<"enter your percentage :";
cin>>page;
if(page==80 && page>=71)
switch(page/=10)
{
case 1:
cout<<"your grade is 'A'"<<endl;
break;
case 2:
cout<<"your grade is 'B'"<<endl;
break;
case 3:
cout<<"your grade is 'C'"<<endl;
break;
case 4:
cout<<"your grade is 'D'"<<endl;
break;
}
return 0;
}
Output:

C++ functions :
Statement_12 : WAP to convert kg to grams
#include<iostream>
using namespace std;
float gram(float kg);
int main()
{
float kg;
cout<<"enter amount in KG :";
cin>>kg;
cout<<"the amount in G is :"<< gram(kg);
return 0;
}
float gram(float kg)
{

float grams;
grams=kg*1000;
return grams;
}
Output:

Statement_13 :
WAP to find factorial of a
number by using function
#include<iostream>
using namespace std;
int fact(int a);
int main()
{
int n;
cout<<"Enter a number"<<endl;
cin>>n;
cout<<"The factorial of n is: "<< n <<" is :"<< fact(n);
return 0;
}
int fact(int a)
{
int factorial=1;
for(int i=1 ; i<=a ; i++)
{
factorial=factorial*i;
}
return factorial;

} 10
Output:

Dry run:

Statement_14 : WAP to find GCD of two numbers by functions


#include <iostream>
using namespace std;
int gcd(int a, int b);
int main()
{
int num1, num2;
cout << "Enter two numbers"<<endl;
cin >> num1 >> num2;
cout << "GCD of " << num1 << " and " << num2 << " is :" <<
gcd( num1, num2 );
return 0;
}
int gcd(int a, int b)
{
if (b == 0)
return a;
else
return gcd(b, a % b);
}
11
Output:

Statement_15 : WAP to find the number of zeros, odd digits & even
digits in a given integer by func()
#include<iostream>
using namespace std;
void analyze(int num);
int main()
{
int num;
cout<<"Enter an integer :";
cin>>num;
analyze(num);
return 0;
}
void analyze(int num)
{
int zeros=0, odd=0 ,even=0;
num=abs(num);
if(num==0)
zeros=1;
while(num>0)
{
int digit=num % 10;
if(digit==0)
{
zeros++;
}
else if(digit%2==0)
{
even++;
}
else
{
odd++;
}
num=num/10;
}
cout<<"The number of Zeros are :"<<zeros<<endl;
cout<<"The number of odd digits are :"<<odd<<endl;
cout<<"The number of even digits are :"<<even<<endl;
}
12

Output:

Statement_16 : WAP to find the area of cylinder by using function


#include<iostream>
using namespace std;
void print(float hieght,float radius);
int main()
{
float hieght,radius,area;
cout<<"Enter hight of cylinder :";
cin>>hieght;
cout<<"Enter radius of cylinder :";
cin>>radius;
print(hieght,radius);
return 0;
}
void print(float hieght,float radius)
{
float area=2*3.14*radius*(hieght+radius);
cout<<"area of cylinder is ="<<area;
}

Output:
13

Statement_17 : WAP to find factorial of 5 natural numbers by


functions
#include <iostream>
using namespace std;
int fact(int n);
int main()
{
for (int num=4; num<=9; num++)
{
cout<< "Factorial of " << num << " is " << fact(num) <<endl;
}
return 0;
}
int fact(int n)
{
int result = 1;
for (int i = 1; i <= n; ++i)
{
result *= i;
}
return result;

{
int i=1, j=1;
for( ; ;
)
{
if(i>5)

break;
else
j+=i;
cout<<"\
n"<<j;
i+=j;
i=i+j;
}
return 0;
}
}
Output:

14

Dry run:

Statement_18 : WAP to make a triangle of asterisks


#include <iostream>
using namespace std;
void print(int n);
int main() {
int rows;
cout <<
"Enter the
number of
rows: ";
cin >> rows;
print(rows);
return 0;
}
void print(int n)
{
for (int i =
1; i <= n; i++)
{
for (int j = 1; j <= i; j++)
{
cout << "*";
}
cout << endl;
}
}
Output:

15

Statement_19 : WAP that displays the table of given integer by


func()
#include<iostream>
using namespace std;
int num;
void table();
int main()
{
cout<<"Enter a number :";
cin>>num;
cout<<"The table of "<<num<<" is"<<endl;
table();
return 0;
}
void table()
{
int i;
for(i=1;
i<=10; i++)
{
cout<<num<<" X "<<i<<" = "<<num*i<<endl;
}
}
Output:

Dry Run:

16

Statement_20 :
WAP to find the square of
7 integer by func()
#include <iostream>
using namespace std;

void sqrnum();

int main()
{
cout << "Square of 1st seven numbers are: " << endl;
sqrnum();
return 0;
}
void sqrnum()
{
for (int i = 1; i <= 7; i++)
{
int square = i * i;
cout << square<<", " ;
}
}
Output:

Dry run:

Arrays
Statement_21 : WAP that gets marks of student & price of items as
input and displays them as output
#include<iostream>
17
using namespace std;
int main()
{
int marks[5],i;
float price[5];
cout<<"enter marks"<<endl;
for(i=1;i<=5;i++)
cin>>marks[i];
cout<<"enter price"<<endl;
for(i=1;i<=5;i++)
cin>>price[i];
cout<<"Here is your array data"<<endl;
for(i=1;i<=5;i++)
{
cout<<"marks of "<<i<<"th student are"<<marks[i]<<endl;
cout<<"price of "<<i<<"th item are"<<price[i]<<endl;
}
return 0;
}
Output:

Statement_22 :
WAP to find largest &
smallest 3 numbers from
given array

#include<iostream>
using namespace std;
int main()
{
int num[15]={8,3,5,7,9,32,54,12,56,89,64,32,24,43,22};
int max1=num[0], max2=num[0], max3=num[0];
int min1=num[0], min2=num[0], min3=num[0];
18
for(int i=1; i<15; i++)
{
if(num[i]>max1)
{
max3=max2;
max2=max1;
max1=num[i];
}
else if(num[i]>max2)
{
max3=max2;
max2=num[i];
}
else if(num[i]>max3)
{
max3=num[i];
}
if(num[i]<min1)
{
min3=min2;
min2=min1;
min1=num[i];
}
else if(num[i]<min2)
{
min3=min2;
min2=num[i];
}
else if(num[i]<min3)
{
min3=num[i];
}
}
cout<<"Largest 3 elements are :"<<max1<<", "<<max2<<",
"<<max3<<endl;
cout<<"Smallest 3 elements are :"<<min1<<", "<<min2<<",
"<<min3<<endl;
return 0;
}
Output:

19

Dry Run:
Statement_23 : WAP to find largest element from given array
#include<iostream>
using namespace std;
int main()
{
int num[15]={68, 4, 3, 6, 7, 23, 25, 35, 4, 67, 22, 54, 11, 9,
34};
int max=num[0];
for(int i=0; i<15; i++)
{
if(num[i]>max)
{
max=num[i];
}
}
cout<<"The largest Element is :"<<max<<endl;
return 0;
}
Output:

Dry Run:

20

Statement_24 : WAP that decides the maximum & minimum b/w


two numbers
#include<iostream>
using namespace std;
int numbers(int num1, int num2, int &max, int &min);
int main()
{
int num1, num2;
int max, min;

cout << "Enter first number: ";


cin >> num1;

cout << "Enter second number: ";


cin >> num2;

numbers(num1, num2, max, min);

cout << "Maximum number: " << max << endl;


cout << "Minimum number: " << min << endl;
return 0;
}
int numbers(int num1, int num2, int &max, int &min)
{
if (num1 > num2)
{
max = num1;
min = num2;
} else {
max = num2;
min = num1;
}
}
Output:

Statement_25 :
WAP to find the repeated
value from given array
#include<iostream>
using namespace std;
int main()
{
int num[15]={3,4,7,6,34,4,6,43,22,10,26,34,55,43,55};
for(int i=0; i<15; i++)
{
for(int j=i+1; j<15; j++) 21
{
if(num[i]==num[j])
{
cout<<num[i]<<" Is a repeated value"<<endl;
}
}
}
return 0;
}
Output:

Dry run:

Arrays in structures
Statement_26 : WAP to add numbers by using structure array
#include<iostream>
using namespace std;

struct sum
{
int num;
float decimal;
};
int main() 22
{
sum s[5];
cout<<"Enter your numbers :\n";
for(int i=0; i<5; i++) {
cout<<"Enter integer numbers :";
cin>>s[i].num;
cout<<"Enter number in decimal :";
cin>>s[i].decimal;
}
float totalSum = 0;
cout << "Sum is :\n";
for (int i = 0; i < 5; i++) {
totalSum += s[i].num + s[i].decimal;
}
cout << "Total Sum is :" << totalSum;
return 0;
}
Output:

Statement_27 : WAP for a book store that gets details of 10


books(price & year) and displays the same by using structures array
#include <iostream>
using namespace std;
struct Bookstore
{
float price;
int year;
};

int main()
{
Bookstore books[10];
cout << "Enter details for 10 books (Price and Year):\n";
for (int i = 0; i < 10; i++)
{
cout << "Book " << i + 1 << ":\n";
cout << "Enter Price: ";
cin >> books[i].price;
cout << "Enter Year: ";
cin >> books[i].year; 23
}
cout << "\nDetails of the 10 books:\n";
for (int i = 0; i < 10; i++)
{
cout << "Book " << i + 1 << " - Price: " << books[i].price <<
", Year: " << books[i].year << endl;
}

return 0;
}
Output:

Structures
Statement_28 : WAP to display marks, grade & cgpa of student by
using structures
#include<iostream>
using namespace std;

struct std1
{
int marks;
char grade;
float cgpa;
} s1;
int main()
{
std1 s2;
cout<<"enter input data"<<endl;
cin>> s1.marks;
cin>>s1.grade;
cin>>s1.cgpa; 24
cout<<"here is your data"<<endl;
cout<< s1.marks;
cout<<s1.grade;
cout<<s1.cgpa;
//for another variable
cout<<"enter input data"<<endl;
cin>> s2.marks;
cin>> s2.grade;
cin>> s2.cgpa;
cout<<"here is your data"<<endl;
cout<< s2.marks;
cout<< s2.grade;
cout<< s2.cgpa;
return 0;
}
Output:

2 dimensional Arrays
Statement_29 : WAP to display data matrix
#include<iostream>
using namespace std;
int main()
{
int i, j;
int arr1[2][2];
cout << "enter data matrix :"<<endl;
for(i=0; i<2; i++)
for(j=0; j<2; j++)
cin>>arr1[i][j];
for(i=0; i<2; i++)
{
cout<<endl;
for(j=0; j<2; j++)
cout<<arr1[i][j];
}
cout<<endl;
return 0;
}
25
Output:

Statement_30 : WAP to calculate the sum of two matrix


#include<iostream>
using namespace std;
int main()
{
int i, j;
int arr1[2][2],arr2[2][2],sum[2][2];
cout <<"enter data of 1st matrix"<<endl;
for(i=0; i<2; i++)
for(j=0; j<2; j++)
cin>>arr1[i][j];
cout<<"enter data of 2nd matrix"<<endl;
for(i=0; i<2; i++)
for(j=0; j<2; j++)
cin>>arr2[i][j];
for(i=0; i<2; i++)
{
for(j=0; j<2; j++)
sum[i][j]=arr1[i][j]+arr2[i][j];
}
for(i=0; i<2; i++)
{
cout<<endl;
for(j=0; j<2; j++)
cout<<sum[i][j];
}
cout<<endl;
return 0;
}
Output:

26
Dry run:

Statement_31 : WAP to calculate product of two matrix


#include<iostream>
using namespace std;
int main()
{
int i, j;
int arr1[2][2],arr2[2][2],prod[2][2];
cout <<"enter data of 1st matrix"<<endl;
for(i=0; i<2; i++)
for(j=0; j<2; j++)
cin>>arr1[i][j];
cout<<"enter data of 2nd matrix"<<endl;
for(i=0; i<2; i++)
for(j=0; j<2; j++)
cin>>arr2[i][j];
for (i=0; i<2; i++)
{
for (j=0; j<2; j++)
{
prod[i][j] = 0;
for (int k=0; k<2; k++)
{
prod[i][j] += arr1[i][k] * arr2[k][j];
}
}
}
for(i=0; i<2; i++)
{
cout<<endl;
for(j=0; j<2; j++)
cout<<prod[i][j];
}
cout<<endl;
return 0;
}

27
Output:

String operator
Statement_32 : WAP by using string operator
#include<iostream>
using namespace std;
int main()
{
char name[]="Klinsman";
int i=0;
while(name[i]!='\0')
{
cout<<" "<<name[i];
i++;
}
return 0;
}

Output:

Pointer operator
Statement_33 : WAP by using Pointer operator
#include<iostream>
using namespace std;
int main()
{
int i=3;
int *p;
p=&i; 28
cout<<"\nAdress of i="<<&i<<endl;
cout<<"contents of p="<<p<<endl;
cout<<"Adress of p is="<<&p;
cout<<"Value of i="<<i<<endl;
cout<<"Value of i="<<*(&i);
return 0;
}
Output:

Additional Tasks
Statement_34 : WAP to find whether the number is prime or
composite?
#include<iostream>
using namespace std;
int main()
{
int n,j,count=0;
cout<<"enter a number"<<endl;
cin>>n;
j==1;
while(j<=n)
{
if(n%j==0)
count++;
j++;
}
if(count==0)
cout<<n<<"PRIME"<<endl;
else
cout<<n<<"COMPOSITE"<<endl;
return 0;
}
Output:
29

Statement_35 : WAP to find the sum of three numbers


#include <iostream>
int main()
{
int a,b,c,sum;
a=1; b=4; c=8;
sum=a+b+c;
return 0;
}

Statement_36 WAP to find whether the given pair is twin prime


pair or not?
#include<iostream>
using namespace std;
int main()
{
int n,p,i,count_1=0,count_2=0;
cout<<"Enter a number"<<endl;
cin>>n;
cout<<"enter 2nd number"<<endl;
cin>>p;
for(i=0; i<=n; i++)
{
if(n%i==0)
count_1++;
}
if(count_1==2)
cout<<n<<"is Prime"<<endl;
else
cout<<n<<"is not a prime"<<endl;
for(i=1; i<=p; i++)
{
if(p%i==0)
count_2++;
}
if(count_2==2)
cout<<p<<"is Prime"<<endl;
else
cout<<p<<"is not a prime"<<endl;
p=n+2;
if(count_1&&count_2==2)
cout<<"is a twin prime pair"<<(n,p)<<endl;
else
cout<<"this is not a twin prime pair"<<endl;
return 0;
}
Output:
30

Statement_37 : WAP to find the given number is palindrome or


not?
#include<iostream>
using namespace std;
int main()
{
int num;
cout<<"Enter a number :";
cin>>num;
int reversed =0, original=num;
for( ; num!=0 ; )
{
reversed=reversed * 10 + num % 10;
num=num/10;
}
if(original==reversed)
cout<<original<<" is a Pelindrome number";
else
cout<<original<<" is not a Palindrome";
return 0;
}

Output:

Statement_38 : WAP that makes a triangle of numbers using nested


loop.
#include <iostream>
using namespace std;

int main() {
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= i; j++) {
cout << j;
}
cout << endl;
}
return 0;
}
Output:
31

Dry Run

Statement_39 : WAP Sum & Product by function


#include <iostream>
using namespace std;
void calculate(int a, int b, int &sum, int &product) {
sum = a + b;
product = a * b;
}
int main() {
int x, y, sum, product;
cout << "Enter two numbers: ";
cin >> x >> y;
calculate(x, y, sum, product);
cout << "Sum: " << sum << endl;
cout << "Product: " << product << endl;
return 0 ;
}
Output:

Statement_40 : WAP to find factorial by function.


#include <iostream>
using namespace std;
int factorial(int n) {
if (n == 0 || n == 1)
return 1;
return n * factorial(n - 1);
}
int main() {
int num; 32
cout << "Enter a number: ";
cin >> num;
cout << "Factorial: "
<< factorial(num)
<< endl;
return 0;
}
Output:

Statement_41 : WAP that swap the value of two numbers by


function.
#include <iostream>
using namespace std;
void swap(int &a, int &b) {
int temp = a;
a = b;
b = temp;
}
int main() {
int x, y;
cout << "Enter two numbers: ";
cin >> x >> y;
swap(x, y);
cout << "After swapping: " << x << " " << y << endl;
return 0;
}
Output:

Dry Run:
33

Statement_42 : WAP that takes 5 numbers as input and print them


as output.
#include <iostream>
using namespace std;
int main() {
int arr[5];
cout << "Enter 5 numbers: ";
for (int i = 0; i < 5; i++) {
cin >> arr[i];
}
cout << "You entered: ";
for (int i = 0; i < 5; i++) {
cout << arr[i] << " ";
}
cout << endl;
retur n 0;
}

Output:

Dry Run:

Statement_43 : WAP to make a rectangle of asterisks.


#include <iostream>
using namespace std;
int main() {
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 3; j++) { 34
cout << "*";
}
cout << endl;
}
return 0;
}
Output:

Statement_44 : WAP to find sum & avg. of 10 numbers.


#include<iostream>
using namespace std;
int main() {
int arr[10], sum = 0;
float average;
cout << "Enter 10 numbers: ";
for (int i = 0; i < 10; i++) {
cin >> arr[i];
sum += arr[i];
}
average = sum / 10.0;
cout << "Sum: " << sum <<
endl;
cout << "Average: " <<
average << endl;
return 0;
}
Output:

Dry Run:
35

Statement_45 : WAP
#include<iostream>
using namespace std;
struct
Student {
string name;
int marks[5];
float cgpa;
char grade;
};
char calculateGrade(float cgpa) {
if (cgpa >= 3.5) return 'A';
else if (cgpa >= 2.5) return 'B';
else return 'C';
}
int main() {
Student student;
cout << "Enter student's name: ";
cin >> student.name; int total = 0;
for (int i = 0; i < 5; i++) {
cout << "Enter marks for subject " << i + 1 << ": ";
cin >> student.marks[i];
total += student.marks[i];
}
student.cgpa = total / 50.0;
student.grade =

calculateGrade(student.cgpa);
cout << "Name: " << student.name << endl;
cout << "CGPA: " << student.cgpa << endl;
cout << "Grade: " << student.grade << endl;
return 0;
}
Output:
Statement_46 : WAP that’s get employee details and print the
same as output.
#include
using namespace std;
struct Employee {
int age;
char gender;
int salary;
};
int main() {
Employee emp;

36
cout << "Enter age: ";
cin >> emp.age;
cout << "Enter gender (M/F): ";
cin >> emp.gender;
cout << "Enter salary: ";
cin >> emp.salary;
cout << "Employee Details:" << endl;
cout << "Age: " << emp.age << endl;
cout << "Gender: " << emp.gender << endl;
cout << "Salary: " << emp.salary << endl;
return 0;
}
Output:

Statement_47 : WAP that ask for a choice for circle & rectangle and
print Area & perimeter of selection.
#include
#include
using namespace std;
float circleArea(int radius) {
return M_PI * radius * radius;
}
float circlePerimeter(int radius) {
return 2 * M_PI * radius;
}
float rectangleArea(float length, float width) {
return length * width;
}
float rectanglePerimeter(float length, float width) {
return 2 * (length + width);
}
int main() {
int choice;
cout << "Choose Shape: 1) Circle 2) Rectangle: ";
cin >> choice;
if (choice == 1) {
int radius;
cout << "Enter radius: ";
cin >> radius;
cout << "Area: " <<

circleArea(radius) << endl;


cout << "Perimeter: " << circlePerimeter(radius) << endl;
} 37
else if (choice == 2) {
float length, width;
cout << "Enter length and width: ";
cin >> length >> width;
cout << "Area: " << rectangleArea(length, width) << endl;
cout << "Perimeter: " << rectanglePerimeter(length, width) << endl;
}
else { cout << "Invalid choice." << endl;
}
return 0;
}
Output:

Statement_48 : WAP to calculate the gross salary.


#include <iostream>
using namespace std;
int main()
{
int hours,payrate,grosssalery;
hours=30;
payrate=1000;
grosssalery=hours*payrate;
cout<<"The value of gross-salery is : "<<grosssalery;
return 0;
}
Output:

Statement_49 :
WAP that indicate
temperature.
#include <iostream>
using namespace std;
int main()
{
int temperature; 39
cout<<"Enter temperature in dgree celsius : ";
cin>>temperature;
if(temperature<30){
cout<<"freezing"<<endl;

} else if (temperature >30)


{
cout<<"boiling : "<<endl;

}else {
cout<<"temperature
is exactly 30 dgree
celsius."<<endl;
}
return 0;
}
Output:
Statement_50 : WAP that tell you about your eligibility of bonus.
#include <iostream>
using namespace std;
int main()
{
int current_year,year_of_joining,year_served;
const int bonus =10000;
cout<<"Enter current year : ";
cin>>currentyear;
cout<<"Enter year of joining : ";
cin>>yearofjoining;
year_served=current_year-year_of_joining;
if(year_served>3){
cout<<"Employee is elligible for bonus : "<<bonus<<endl;
}else {
// do nothing
}
Output:

39

You might also like