# some beginner codes

```Lab 9 Fatimah Hatem Elsayed 2021/10731
Exercise 1:
#include &lt;iostream&gt;
using namespace std;
class rectangle {
private :
double height, width;
public :
rectangle() {
height = 1.0, width = 1.0;
}
rectangle(double h, double w)
{
height = h, width = w;
}
double getPer()
{
return (2*(height)+2*(width));
}
double getArea() {
return height * width;
}
};
int main()
{
int l, w;
cout &lt;&lt; &quot;Enter length and width: &quot;;
cin &gt;&gt; l &gt;&gt; w;
rectangle r(l,w);
cout &lt;&lt; &quot;Area: &quot; &lt;&lt; r.getArea();
cout &lt;&lt; &quot;\nPerimeter: &quot; &lt;&lt; r.getPer();
}
Exercise 2:
#include &lt;iostream&gt;
#include &lt;fstream&gt;
using namespace std;
class Fan
{
private:
int speed; bool on; double radius;
public:
Fan()
{
speed = 1, on = false, radius = 5.0;
}
void setSpeed(int s)
{
this-&gt;speed = s;
}
{
}
void setCondition(bool o)
{
this-&gt;on = o;
}
int getSpeed()
{
return speed;
}
{
}
bool getCondition()
{
return on;
}
};
int main()
{
Fan fan1, fan2;
int s1 = 3, s2 = 2;
double r1 = 10, r2 = 5;
bool con1 = true, con2 = false;
cout &lt;&lt; &quot;Fan 1:\n&quot; &lt;&lt; &quot;Speed: &quot; &lt;&lt; fan1.getSpeed() &lt;&lt; &quot;\nRadius: &quot; &lt;&lt; fan1.getRadius() &lt;&lt; &quot;\nCondtion: &quot;;
if (fan1.getCondition() == true)
{
cout &lt;&lt; &quot;on&quot;;
}
else
{
cout &lt;&lt; &quot;off&quot;;
}
cout &lt;&lt; &quot;\nFan 2:\n&quot; &lt;&lt; &quot;Speed: &quot; &lt;&lt; fan2.getSpeed() &lt;&lt; &quot;\nRadius: &quot; &lt;&lt; fan2.getRadius() &lt;&lt; &quot;\nCondtion: &quot;;
if (fan2.getCondition() == true)
{
cout &lt;&lt; &quot;on&quot;;
}
else
{
cout &lt;&lt; &quot;off&quot;;
}
}
Exercise 3:
#include &lt;iostream&gt;
using namespace std;
class Account {
private:
int id;
double bal;
double annualInterestRate;
public:
Account() {
id = 0, bal = 0; annualInterestRate = 0;
}
double getMonthlyInterestRate(double annualInterestRate) {
return annualInterestRate / 12;
}
bool setid(int id)
{
this-&gt;id = id;
return true;
}
bool setbal(double bal)
{
this-&gt;bal = bal;
return true;
}
bool setint(double annualInterestRate) {
this-&gt;annualInterestRate = annualInterestRate;
return true;
}
double withdraw(int w) {
return bal - w;
}
double deposit(int d) {
return bal + d;
}
};
int main()
{
int id;
double bal, i,w,d;
Account r;
cout &lt;&lt; &quot;Enter ID: &quot;;
cin &gt;&gt; id;
r.setid(id);
cin &gt;&gt; bal;
r.setbal(bal);
i = 4.5;
cout &lt;&lt; &quot;\nYour annual interest rate is: &quot;&lt;&lt; r.setint(i);
cout &lt;&lt; &quot;\nEnter the amount you wish to withdraw: &quot;;
cin &gt;&gt; w;
cout &lt;&lt; &quot;Your new balance is: &quot; &lt;&lt; r.withdraw(w);
cout &lt;&lt; &quot;\nEnter the amount you want to deposit: &quot;;
cin &gt;&gt; d;
cout &lt;&lt; &quot;Your balance is now: &quot; &lt;&lt; r.deposit(d);
}
Exercise 4:
#include &lt;iostream&gt;
#include &lt;fstream&gt;
using namespace std;
class MyPoint
{
private:
double x, y;
public:
MyPoint() { x = 0, y = 0; };
MyPoint(double x, double y)
{
this-&gt;x = x;
this-&gt;y = y;
}
void setX(double x)
{
this-&gt;x = x;
}
double getX()
{
return x;
}
void sety(double y)
{
this-&gt;y = y;
}
double gety()
{
return y;
}
void distance(double x, double y)
{
cout &lt;&lt; &quot;(&quot; &lt;&lt; (x - this-&gt;x) &lt;&lt; &quot;,&quot; &lt;&lt; (y - this-&gt;y)&lt;&lt; &quot;)&quot;;
}
};
int main()
{
MyPoint p1;
double x = 0, x1 = 10, y = 0, y1 = 30.5;
p1.setX(x), p1.sety(y);
p1.distance(x1, y1);
}
```