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

PROGRAMMING

The document contains 3 programs. Program 1 calculates the area of triangles and rectangles by taking user input for base/length and height/width. Program 2 defines classes for person, employee and student and sets/gets their attributes. Program 3 reads data from an input file, calculates sum and product of numbers on each line, and writes the output to another file.

Uploaded by

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

PROGRAMMING

The document contains 3 programs. Program 1 calculates the area of triangles and rectangles by taking user input for base/length and height/width. Program 2 defines classes for person, employee and student and sets/gets their attributes. Program 3 reads data from an input file, calculates sum and product of numbers on each line, and writes the output to another file.

Uploaded by

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

PROGRAM 1

#include <iostream>
using namespace std;
class shape {
public:
void triangle()
{
int base, height, area;
cout << "Enter Triangle Base " << endl;
cin >> base;
cout << "Enter Triangle Height " << endl;
cin >> height;
area = (base * height) / 2;
cout << "Area of Triangle is " << area;
}
void rectangle()
{
int length, width, area;
cout << "Enter Rectangle Length " << endl;
cin >> length;
cout << "Enter Rectangle Width " << endl;
cin >> width;
area = length * width;
cout << "Area of Rectangle is " << area;
}
};
int main()
{
shape a;
int ch;
cout << " * **Menu * **\nn1.Area of Triangle\nn2.Area of Rectangle";
cout << "\nn3.Exit\nEnter your choice : ";
cin >> ch;
switch (ch)
{
case 1:a.triangle(); break;
case 2:a.rectangle(); break;
case 3:return 0;
}
return 0;
}

//////////////////////////////////////

PROGRAM 2
#include <iostream>
using namespace std;
class person {
private:
char name;
int age;
string address;
public:
char getName()
{
return name;
}
int getAge()
{
return age;
}
string getAddress()
{
return address;
}
void setName(char n)
{
name = n;
cout << "Enter Name";
cin >> n;
}
void setAge(int a)
{
age = a;
cout << "Enter age";
cin >> a;
}
void setAddress(string ad)
{
address = ad;
cout << "Enter address";
cin >> ad;
}
void display() {
cout << "Name :" << name;
cout << "Age :" << age;
cout << "Address :" << address;
}
};
class employee :public person {
private:
int empid,salary;
public:
int getEmpid()
{
return empid;
}
int getSalary()
{
return salary;
}
void setEmpid(int em)
{
empid = em;
cout << "Enter Employee Id ";
cin >> em;
}
void setSalary(int ss)
{
salary = ss;
cout << "Enter Salary ";
cin >> ss;
}
void display()
{
cout << "Employee ID : " << empid<<endl;
cout << "Salary " << salary << endl;
}

};
class student :public person {
int regid;
double cgpa;
int getRegid()
{
return regid;
}
double getCgpa()
{
return cgpa;
}
void setRegid(int rr)
{
regid = rr;
cout << "Enter Reg Id";
cin >> rr;
}
void setCgpa(double cg)
{
cgpa = cg;
cout << "Enter Cgpa";
cin >> cg;
}
void display()
{
cout << "Student ID " << regid<<endl;
cout << "CGPA " << cgpa << endl;
}

};
int main()
{
person p;
employee e;
student s;

}
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
PROGRAM 3
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
fstream file;
file.open("input.txt", ios::out);
ifstream inputfile("input.txt");
ofstream outputfile("output.txt");

int A, B, product, line = 0;

outputfile << " Full Name" << endl


<< "A" << "\t" << "B" << "\t"
<< "Sum" << "\t" << "Product" << endl;
while (!inputfile.eof())
{
inputfile >> A >> B;
outputfile << A << "\t" << B << "\t" << A+B << "\t"<< A*B<< endl;
line++;
}

cout << "Number of lines " << line << endl;


return 0;
}

You might also like