0% found this document useful (0 votes)
40 views13 pages

Object Oriented Programming (Assignmnet1)

The document contains 3 programs written in C++ to demonstrate user defined functions. Program 1 creates a simple bank management system using functions to open an account, deposit money, withdraw money, and display account details. Program 2 defines a function to calculate income tax on a salary based on tax brackets. Program 3 demonstrates passing arguments to functions by value and by reference by changing variable values inside and outside functions.

Uploaded by

mozalfa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
40 views13 pages

Object Oriented Programming (Assignmnet1)

The document contains 3 programs written in C++ to demonstrate user defined functions. Program 1 creates a simple bank management system using functions to open an account, deposit money, withdraw money, and display account details. Program 2 defines a function to calculate income tax on a salary based on tax brackets. Program 3 demonstrates passing arguments to functions by value and by reference by changing variable values inside and outside functions.

Uploaded by

mozalfa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 13

Assignment Title: User defined function

Course Title: Object Oriented Programming


Class: ADP- IT 2nd Semester

Submitted by: M.Mozalfa Ilyas


Roll No: 21012456-026
Submitted to: Mam Zainab Noor
Submission date: 05-06-2022

UOG G.T. ROAD GUJRAT


Assignment no#1:

PROGRAM 1:
Write a program to build a simple Bank Management System using C++ which can
perform the following operations:
Open account
Deposit Money
Withdraw Money
Display Account
Trick: Take the data from user
Method: user defined function and structure
SOLUTION:
#include<iostream>
using namespace std;
struct banksystem
{
char accountholdername[30];
char accountholderadress[50];
int accountnumber;
float balance;
}b;
void openaccount()
{
cout<<"Enter your name:"<<endl;
cin>>b.accountholdername;
cout<<"Enter your adress:"<<endl;
cin>>b.accountholderadress;
cout<< "Enter your account number:"<<endl;
cin>> b.accountnumber;
cout<<"Enter amount you want to add in account to start:"<<endl;
cin>>b.balance;
cout<< "***ACCOUNT SUCCESSFULLY OPENED***";
}
void displayaccount()
{
cout<<"***ACCOUNT INFORMATION***";
cout<<"\nName of accountholder: "<<b.accountholdername;
cout<<"\nAdress of accountholder: "<<b.accountholderadress;
cout<< "\nYour account number is: "<<b.accountnumber;
cout<<"\n Balance in your account: "<<b.balance;
}
void depositmoney()
{
int addamount;
cout<<"Enter money you want to deposit:";
cin>>addamount;
b.balance=addamount+b.balance;
cout<<"Total amount in your account after depositing is:"<<b.balance;
}
void withdrawmoney()
{
int withmoney;
cout<<"Enter ammount you want to withdraw:";
cin>>withmoney;
b.balance=b.balance-withmoney;
cout<<"Total amount in your account after withdrawing is::"<<b.balance;
}
void showchoice()
{
cout<<"\n1.Open account"<<endl;
cout<<"\n2.Display account"<<endl;
cout<<"\n3.Deposit money"<<endl;
cout<<"\n4.Withdraw money"<<endl;
cout<<"\n5.Exit"<<endl;
cout<<"Enter your choice: ";
}
int main()
{
int choice=0;
do
{
showchoice();
cin>>choice;
switch(choice)
{
case 1:
openaccount();
break;
case 2:
displayaccount();
break;
case 3:
depositmoney();
break;
case 4:
withdrawmoney();
break;
case 5:
cout<< "***THANK YOU FOR COMING***";
break;
default:
cout<<"***INVALID ENTRY***”;
break;
}
}while(choice!=5);
return 0;
}

OUTPUT:
1.Open account
2.Display account
3.Deposit money
4.Withdraw money
5.Exit
Enter your choice:1
Enter your name:
mozalfa
Enter your adress:
gujrat
Enter your account number:
56231458
Enter amount you want to add in account to start :
5000
***ACCOUNT SUCCESSFULLY OPENED***
1.Open account
2.Display account
3.Deposit money
4.Withdraw money
5.Exit
Enter your choice:2
***ACCOUNT INFORMATION***
Name of accountholder: mozalfa
Adress of accountholder: gujrat
Your account number is: 56231458
Balance in your acoount:5000
1.Open account
2.Display account
3.Deposit money
4.Withdraw money
5.Exit
Enter your choice:3
Enter money you want to deposit:2000
Total amount in your account after depositing is:7000
1.Open account
2.Display account
3.Deposit money
4.Withdraw money
5.Exit
Enter your choice:4
Enter ammount you want to withdraw:3000
Total amount in your account after withdrawing is::4000
1.Open account
2.Display account
3.Deposit money
4.Withdraw money
5.Exit
Enter your choice:5
***THANK YOU FOR COMING***
1.Open account
2.Display account
3.Deposit money
4.Withdraw money
5.Exit
Enter your choice: 6
***INVALID ENTRY***

PROGRAM 2:
Write a function that accepts a salary and returns the tax according to following
rules:
No tax for first Rs 1000.
5% for second Rs.1000.
4% for third Rs 1000.
3% for remain untaxed salary
For example, if salary is Rs 4000 then the tax is Rs 120
SOLUTION:
#include<iostream>
using namespace std;
struct tax
{
int employeeno;
char employeename[20];
int employeesalary;
double employeetax;
} t;
void get()
{
cout<<"***ENTER THE DEATILS OF EMPLOYEE***" <<endl;
cout<<"Enter employee number: ";
cin>>t.employeeno;
cout<<"Enter employee name: ";
cin>>t.employeename;
cout<<"Enter employee salary: ";
cin>>t.employeesalary;
}
void put()
{
cout<<"***ENTERED EMPLOYEE DETAILS ARE***";
cout<<"\nEmployee number: "<<t.employeeno;
cout<<"\nEmployee name: "<<t.employeename;
cout<<"\nEmployee salary: "<<t.employeesalary;
cout<<"\nEmployee tax is: "<<t.employeetax;
}
void calculatetax()
{
if(t.employeesalary<=1000)
{
t.employeetax=0;
}
else if (t.employeesalary<=2000)
{
t.employeetax= (t.employeesalary-1000)*0.05;
}
else if (t.employeesalary<=3000)
{
t.employeetax=(t.employeesalary-2000)*0.04+1000*0.05;
}
else if (t.employeesalary>3000)
{
t.employeetax= (t.employeesalary-3000)*0.03+1000*0.04+1000*0.05;
}
}
int main()
{
get();
calculatetax();
put();
return 0;
}

OUTPUT 1:
***ENTER THE DEATILS OF EMPLOYEE***
Enter employee number: 560
Enter employee name: mozalfa
Enter employee salary: 4000
***ENTERED EMPLOYEE DETAILS ARE***
Employee number: 560
Employee name: mozalfa
Employee salary: 4000
Employee tax is: 120

OUTPUT 2:
***ENTER THE DEATILS OF EMPLOYEE***
Enter employee number: 601
Enter employee name: ilyas
Enter employee salary: 60000
**ENTERED EMPLOYEE DETAILS ARE***
Employee number: 601
Employee name: ilyas
Employee salary: 60000
Employee tax is: 1800

PROGRAM 3:
Write a program that gets two numbers, one should be passed by value and other
should be passed by reference and then check the original variable whether their
values have been changed or not.
SOLUTION:
#include <iostream>
using namespace std;
void change(int);
void change(int*);
int main()
{
cout<<"***USING CALL BY VALUE***"<<endl;
int a;
cout<<"Enter a value 'a':"<<endl;
cin>>a;
cout<<"Value of 'a' before function calling:\n"<<a<<endl;
change(a);
cout<<"Value of 'a' after function calling:\n"<<a<<endl;
cout<<"\n***USING CALL BY REFRENCE***"<<endl;
int b;
int*p;
cout <<"Enter a value 'b':"<<endl;
cin>>b;
p=&b;
cout<<"Value of 'b' before function calling:\n"<<*p<<endl;
change(p);
cout<<"Value of 'b' after function calling:\n"<<*p<<endl;
return 0;
}
void change(int a)
{
a=a+10;
}
void change(int *p)
{
*p=*p+10;
}

OUTPUT 1:
***USING CALL BY VALUE***
Enter a value 'a':
4
Value of 'a' before function calling:
4
Value of 'a' after function calling:
4

***USING CALL BY REFRENCE***


Enter a value 'b':
5
Value of 'b' before function calling:
5
Value of 'b' after function calling:
15

Output 2:
***USING CALL BY VALUE***
Enter a value 'a':
3
Value of 'a' before function calling:
3
Value of 'a' after function calling:
3

***USING CALL BY REFRENCE***


Enter a value 'b':
3
Value of 'b' before function calling:
3
Value of 'b' after function calling:
13

You might also like