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

CPP PROGRAM

The document contains multiple C++ programming tasks, including finding the area of a triangle, circle, and rectangle using function overloading, as well as calculating simple interest with default values. It also includes programs for copying text file contents, overloading the unary ++ operator, and swapping values using call by reference. Additionally, it features a class for managing employee data and customer information with salary calculations.

Uploaded by

ganeshnavale942
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

CPP PROGRAM

The document contains multiple C++ programming tasks, including finding the area of a triangle, circle, and rectangle using function overloading, as well as calculating simple interest with default values. It also includes programs for copying text file contents, overloading the unary ++ operator, and swapping values using call by reference. Additionally, it features a class for managing employee data and customer information with salary calculations.

Uploaded by

ganeshnavale942
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

23.

Write a C++ program to find area of triangle,


1.write a c++ program to find the circle,and rectangle using function overloading.
maximum of two integer numbers
#include<iostream.h>
using inline function
#include<conio.h>
#include <stdio.h> const float pi=3.14;
inline int max(int x, int y) { float area(float n,float b,float h){
float ar;
return x > y ? x : y; ar=n*b*h;
} return ar; }
float area(float r){
int main() { float ar;
int a = 110, b = 120; ar=pi*r*r;
return ar; }
printf("Maximum of %d and %d is
float area(float l,float b){
%d\n", a, b, max(a, b));
float ar;
a = -110, b = -120; ar=l*b;
return ar; }
printf("Maximum of %d and %d is
void main(){
%d\n", a, b, max(a, b));
float b,h,r,l;
return 0; float result;
} clrscr();
cout<<“\nEnter the Base & Hieght of Triangle:\n”;
cin>>b>>h;
result=area(0.5,b,h);
cout<<“\nArea of Triangle: “<<result<<endl;
cout<<“\nEnter the Radius of Circle: \n”;
cin>>r;
result=area(r);
cout<<“\nArea of Circle: “<<result<<endl;
cout<<“\nEnter the Length & Bredth of
Rectangle: \n”;
cin>>l>>b;
result=area(l,b);
cout<<“\nArea of Rectangle: “<<result<<endl;
getch(); }
write a c++ program overload unary++ oprator
write c++ program to swap the #include<iostream.h>
values using call by reference #include<conio.h>
methiod class complex {
#include <iostream> int a, b, c;
using namespace std; public:
void swap(int x, int y) { complex() {
int temp = x; }
x = y; void getvalue() {
y = temp; cout << "Enter the Two Numbers:";
} cin >> a>>b;
int main() { }
int a = 40; void operator++() {
int b = 50; a = ++a;
cout << "Before swap: a = " << a << " b = ++b;
b = " << b << endl; }
swap(a, b); void operator--() {
cout << "After swap: a = " << a << " b a = --a;
= " << b << endl; b = --b;
return 0; }
} void display() {
2.write c ++ program to calcute the cout << a << "+\t" << b << "i" << endl;
simple interst (using default value }
for rate) };
#include<iostream> void main() {
using namespace std; clrscr();
int main() complex obj;
{ obj.getvalue();
float p, r, t, si; obj++;
cout<<"Enter Principle Amount: "; cout << "Increment Complex Number\n";
cin>>p; obj.display();
cout<<"Enter Rate of Interest: "; obj--;
cin>>r; cout << "Decrement Complex Number\n";
cout<<"Enter Time Period: "; obj.display();
cin>>t; getch();
si = (p*r*t)/100; }
cout<<"\nSimple Interest Amount:
"<<si;
cout<<endl;
return 0;
}
Write a C++ program to copy the #include<conio.h>
contents of a text file into another #include<iostream.h>
text file. #include<iomanip.h> //manipulator
#include <fstream> class emp
#include <iostream> { public:
using namespace std; int eid; //eid=employee id
int main() float bsal,hra,da,gsal; //bsal=basic salary ,
{ hra=HRA , da=DA , gsal=Gross salary
string line; char name[10]; //name=name of employee
ifstream ini_file{ void accept() {
"original.txt" cout<<"Enter employee id: ";
}; cin>>eid;
ofstream out_file{ "copy.txt" }; cout<<"Enter employee name: ";
if (ini_file && out_file) { cin>>name;
while (getline(ini_file, line)) { cout<<"Enter basic salary: ";
out_file << line << "\n"; cin>>bsal; }
} void disp() {
cout << "Copy Finished \n"; cout.precision(2); //manipulator
} cout.left;
else { cout<<"employee id: "<<setw(20)<<eid<<endl;
printf("Cannot read File"); cout<<"employee name:
} "<<setw(20)<<name<<endl;
ini_file.close(); cout<<"basic salary: "<<bsal<<endl;
out_file.close(); cout<<"HRA: "<<hra<<endl;
return 0; cout<<"DA: "<<da<<endl;
} cout<<"Gross salary: "<<gsal<<endl; }
void cal() {
5.Write a C++ program to create a hra=((30.0/100)*bsal);
class customer which contains data da=((20.0/100)*bsal);
members as C_id, C_name, gsal=bsal+hra+da; }
C_Salary. Write member functions };
to accept and display customer int main(){
information, also display emp e; //creating instance of class emp
information of customer having e.accept(); //calling member functions
maximum salary e.cal();
e.disp();
getch();
return(0);
}

You might also like