0% found this document useful (0 votes)
43 views

C++ Function Assignment

This program shows how to calculate an employee's gross salary based on their basic salary. It takes the basic salary as input and calculates HRA and DA based on salary ranges. It then outputs the total gross salary.

Uploaded by

Dejenie
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

C++ Function Assignment

This program shows how to calculate an employee's gross salary based on their basic salary. It takes the basic salary as input and calculates HRA and DA based on salary ranges. It then outputs the total gross salary.

Uploaded by

Dejenie
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

1.

Write a program in C++ that calculates the addition,


subtraction, multiplication, or division of any two given
numbers based on the user's choice using a user-defined
function.
#include<iostream>
using namespace std;
float addFun(float, float);
float subFun(float, float);
float mulFun(float, float);
float divFun(float, float);
int main()
{
float num1, num2;
char op;
cout<<"Enter Two Numbers: ";
cin>>num1>>num2;
cout<<"Enter the Operator (+, -, *, /): ";
cin>>op;
if(op=='+')
cout<<endl<<"Addition Result = "<<addFun(num1, num2);
else if(op=='-')
cout<<endl<<"Subtraction Result = "<<subFun(num1, num2);
else if(op=='*')
cout<<endl<<"Multiplication Result = "<<mulFun(num1, num2);
else if(op=='/')
cout<<endl<<"Division Result = "<<divFun(num1, num2);
else
cout<<endl<<"Wrong Operator!";
cout<<endl;
return 0;
}
float addFun(float a, float b)
{
return a+b;
}
float subFun(float a, float b)
{
return a-b;
}
float mulFun(float a, float b)
{
return a*b;
}
float divFun(float a, float b)
{
return a/b;
}
2. Applying Object oriend Programming Worksheet 1
1. Write a C++ program to calculate a student’s grade based on the following range.

> =90 A+
>= 80 A
>= 70 B+
>= 60 B
>= 50 C
>=40 D
>=30 E
>= 0 F
2. This program shows the greatest
number between three numbers using if-else-if statement. It takes three numbers as
input from keboard and output the greatest number.
3. Write a C++ program to print out the following triangle

*
**
***
****
3. C++ program to find Fibonacci Series upto n=15.
4. Write a program using function which accept two integers as an argument and return its sum.
Call this function from main( ) and print the results in main( ).
5. Question 2 Write a function to calculate the factorial value of any integer as an argument.
Call this function from main( ) and print the results in main( ).
6. Question 3 Write a function that receives two numbers as an argument and display all prime
numbers between these two numbers. Call this function from main( ).

C++ Program which takes input a grade and display Grade


Points Average GPA
#include<iostream.h>
int main()
{
char grade; double gpa=0.0;
cout<<"Enter your Grade= ";
cin>>grade;
switch(grade)
{
case'A':
case'a':
gpa=4.0;
cout<<"your GPA is "<<gpa;
break;
case'B':
case'b':
gpa=3.0;
cout<<"your GPA is "<<gpa;
break;
case'C':
case'c':
gpa=2.0;
cout<<"your GPA is "<<gpa;
break;
case'D':
case'd':
gpa=1.0;
cout<<"your GPA is "<<gpa;
break;
case'F':
case'f':
gpa=0.0;
cout<<"your GPA is "<<gpa;
break;

default:
cout<<"invalid grade entered";
break;
}
return 0;
}

C++ program to find Fibonacci Series upto given range. This C++ program use simple
logic to get the concept of writing code in C++ for Fibonacci Series

1. #include<iostream.h>
2. int main()
3. {
4. int range, first = 0, second = 1, fibonicci=0;
5. cout << "Enter Range for Terms of Fibonacci Sequence: ";
6. cin >> range;
7. cout << "Fibonicci Series upto " << range << " Terms "<< endl;
8. for ( int c = 0 ; c < range ; c++ )
9. {
10. if ( c <= 1 )
11. fibonicci = c;
12. else
13. {
14. fibonicci = first + second;
15. first = second;
16. second = fibonicci;
17. }
18. cout << fibonicci <<" ";
19. }
20. return 0;
21. }
========================================================================================================================

This program shows the greatest number between three


numbers using if-else-if statement. It takes three numbers as
input from user and output the greatest number.
1. #include<iostream.h>
2. int main()
3. {
4. int num1,num2,num3;
5. cout<<" Enter value for first number";
6. cin>>num1;
7.
8. cout<<" Enter value for second number";
9. cin>>num2;
10.
11. cout<<" Enter value for third number";
12. cin>>num3;
13. if(num1>num2&&num1>num3)
14. {
15. cout<<" First number is greatest:"<<endl<<"whick
is= "<<num1;
16. }
17. else if(num2>num1&&num2>num3)
18. {
19. cout<<" Second number is greatest"<<endl<<"whick
is= "<<num2;
20. }
21. else
22. {
23. cout<<" Third number is greatest"<<endl<<"whick is=
"<<num3;
24. }
25. return 0;
26. }

#Include<include .h>
int main(int argc, char *argv[])
{
//Switches (case Structure) //
int marks;
cout<<"\t\nEnter the makrs = ";
cin>>marks;
cout<<"\t\nCongratulations Your Grade is = ";
switch (marks)
{
case 90:
cout<<"A\n\n\n";
break;
case 80:
cout<<"B\n\n\n";
break;
case 70:
cout<<"C\n\n";
break;
default:
cout<<"Sorry Try Again Student\n\n";
break;
}
system("PAUSE");
return 0;
}
In a company an employee is paid as under:
If his basic salary is less than Rs. 1500, then HRA = 10% of basic salary and DA = 90% of basic
salary.
If his salary is either equal to or above Rs. 1500, then HRA = Rs. 500 and DA = 98% of basic
salary.
If the employee's salary is input by the user write a program to find his gross salary.

Write a program to enter the numbers till the user wants and at the end it should display the
maximum and minimum number entered

Write C++ program to print following pattern:


i) ********** ii) * iii) *
********** ** **
********** *** ***
********** **** ****
***** *****
iv) * v) 1 vi) 1
*** 222 212
***** 33333 32123
******* 4444444 4321234
********* 555555555 543212345

C++ Source Code of Gross salary program


1 #include<iostream>
2 using namespace std;
3 int main ()
4 {
5 int salary,gross,hra,da;
6 cout<<"enter the basic salary of the employee."<<endl;
7 cin>>salary;
8 if(salary<= 10000)
9 {
10 da=salary*20/100;
11 hra=salary*80/100;
12 gross=salary+da+hra;
13 cout<<"the gross salary of the employee is"<<endl<<gross;
14 }
15 if(salary<= 20000)
16 {
17 da=salary*25/100;
18 hra=salary*90/100;
19 gross=salary+da+hra;
20 cout<<"the gross salary of employee is"<<endl<<gross;
21 }
22 else if(salary>20000)
23 {
24 da=salary*30/100;
25 hra=salary*95/100;
26 gross=salary+da+hra;
27 cout<<"the gross salary of employee is"<<endl<<gross;
28 }
29 else
30 {
31 cout<<"you have no salary"<<endl;
32 }
33 }

You might also like