0% found this document useful (0 votes)
49 views6 pages

Oop 1

This document contains code for 3 programs that create classes in C++. The first program creates a circle class that stores the radius of a circle and calculates the area, diameter, and circumference. The second program creates a population class that stores population values and calculates birth and death rates. The third program creates a temperature class that checks if different substances boil or freeze at a given temperature.

Uploaded by

Abdul Habib Mir
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)
49 views6 pages

Oop 1

This document contains code for 3 programs that create classes in C++. The first program creates a circle class that stores the radius of a circle and calculates the area, diameter, and circumference. The second program creates a population class that stores population values and calculates birth and death rates. The third program creates a temperature class that checks if different substances boil or freeze at a given temperature.

Uploaded by

Abdul Habib Mir
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/ 6

BCSF15A-001 Hamza Habib Mir

OBJECT ORIENTATED PROGRAMMING (ASSIGNMENT)

PROGRAM WHICH CREATES A CLASS AND ASKS FOR A RADIUS OF A CRICLE AND THEN GIVES THE
AREA, DIAMETER AND CIRCUMFRENCE.
#include <iostream>
#include <conio.h>
#define pi 3.14159
using namespace std;
class circle
{
private:
double radius;
public:
circle();
void setRadius(double);
double getRadius() const;
double getArea() const;
double getDiameter() const;
double getCircumfrence()const;
};
circle::circle()
{
radius=0;
}
void circle::setRadius(double r)
{
radius = r;
}

double circle::getRadius() const


{
return radius;
}
double circle::getArea() const
{
return pi*pi*radius;
}
double circle::getDiameter() const
{
return radius * 2;
}

double circle::getCircumfrence() const


{
return 2 * pi*radius;
}
int main()
{
circle object;
double radius;
cout << "enter the radius: ";
cin >> radius;
object.setRadius(radius);
object.getRadius();
cout << "area=" << object.getArea() << endl;
cout << "diameter=" << object.getDiameter() << endl;
cout << "circumference=" << object.getCircumfrence();
getch();
return 0;
}

A PROGRAM THAT CREATES A CLASS AND STORES A VALUE OF POPULATION,NO OF BIRTHS AND NO OF
DEATHS AND THEN GIVES THE BIRTH AND DEATH RATE OF A SPECIFIC TIME PERIOD.
#include <iostream>
#include <conio.h>
using namespace std;
class Population
{
private:
double population;
double num_births;
double num_deaths;
public:
void setpopulation(double);
double getpopulation() const;
void setbirths(double);
double getbirths() const;
void setdeaths(double);
double getdeaths() const;
double birthrate() const;
double deathrate() const;
};
void Population::setpopulation(double p)
{
population = p;
}
double Population::getpopulation() const
{
return population;
}
void Population::setbirths(double b)
{
num_births = b;
}
double Population::getbirths() const
{
return num_births;
}
void Population::setdeaths(double d)
{
num_deaths = d;
}
double Population::getdeaths() const
{
return num_deaths;
}
double Population::birthrate() const
{
double b_rate;
b_rate = num_births / population;
return b_rate;
}
double Population::deathrate() const
{
double d_rate;
d_rate = num_deaths / population;
return d_rate;
}
int main()
{
Population mass;
double births, deaths, population, birth_rate, death_rate;
cout << "Enter the population:";
cin >> population;
if (population < 1)
{
cout << "Invalid entry !\n";
cout << "Input the amount of population again:";
cin >> population;
}
cout << "Enter the number of births:";
cin >> births;
if (births < 0)
{
cout << "Invalid entry !\n";
cout << "Input the number of births again:";
cin >> births;
}
cout << "Enter the number of deaths:";
cin >> deaths;
if (deaths < 0)
{
cout << "Invalid entry !\n";
cout << "Input the amount of deaths again:";
cin >> deaths;
}
mass.setpopulation(population);
mass.getpopulation();
mass.setbirths(births);
mass.getbirths();
mass.setdeaths(deaths);
mass.getdeaths();
cout << "Birth rate= " << mass.birthrate() << endl;
cout << "Death rate= " << mass.deathrate();
getch();
return 0;
}

A PROGRAM THAT ASKS ABOUT AND TEMPERATURE OF A SUBSTANCE AND THEN TELLS WHETHER IT
BOILS OR FREEEZES AT THE TEMPERATURE.

#include<iostream>
#include<conio.h>
using namespace std;
class Temperature
{
private:
double temperature;
public:
void set_Temperature(double i);
double get_Temperature();
bool is_ethyl_boiling();
bool is_ethyl_freezing();
bool is_oxygen_boiling();
bool is_oxygen_freezing();
bool is_water_boiling();
bool is_water_freezing();
};
void Temperature::set_Temperature(double i)
{
cout << "Enter the temperature : ";
cin >> i;
temperature = i;
}
double Temperature::get_Temperature()
{
return temperature;
}
bool Temperature::is_ethyl_boiling()
{
if (temperature >= 172)
{
return true;
}
return false;
}
bool Temperature::is_ethyl_freezing()
{
if (temperature <= -173)
{
return true;
}
return false;
}
bool Temperature::is_oxygen_boiling()
{
if (temperature >= -306)
{
return true;
}
return false;
}
bool Temperature::is_oxygen_freezing()
{
if (temperature <= -362)
{
return true;
}
return false;
}
bool Temperature::is_water_boiling()
{
if (temperature >= 212)
{
return true;
}
return false;
}
bool Temperature::is_water_freezing()
{
if (temperature <= 32)
{
return true;
}
return false;
}
int main()
{
Temperature objects;
double temperature = 0;
objects.set_Temperature(temperature);
temperature = objects.get_Temperature();
if (objects.is_ethyl_freezing())
cout << "Ethyl Alcohol will Freeze at " << temperature << " Fahrenheit" << endl;
if (objects.is_ethyl_boiling())
cout << "Ethyl Alcohol will Boil at " << temperature << " Fahrenheit" << endl;
if (objects.is_oxygen_freezing())
cout << "Oxygen will Freeze at " << temperature << " Fahrenheit" << endl;
if (objects.is_oxygen_boiling())
cout << "Oxygen will Boil at " << temperature << " Fahrenheit" << endl;
if (objects.is_water_freezing())
cout << "Water will Freeze at " << temperature << " Fahrenheit" << endl;
if (objects.is_water_boiling())
cout << "Water will Boil at " << temperature << " Fahrenheit" << endl;
getch();
return 0;
}

You might also like