Question 1- 1.cpp code:
#include #include using namespace std;
double SquareRoot(double d)
{
double x=1;
for(int i=0;i<1000;++i) { double t=d/x; x=(x+t)/2; } return x; } int main() { double res=SquareRoot(17); cout.setf(ios::fixed); cout << setprecision(4) << res << endl; return 0; }
Rectangle.cpp code
#include "Rectangle.h"
Rectangle::Rectangle(int h,int w)
{
height=h;
width=w;
}
Rectangle::Rectangle(const Rectangle &other)
{
height=other.height;
width=other.width;
}
Rectangle & Rectangle::operator=(const Rectangle &other)
{
height=other.height;
width=other.width;
return *this;
}
int Rectangle::getheight()
{
return height;
}
int Rectangle::getwidth()
{
return width;
}
void Rectangle::setheight(int h)
{
height=h;
}
void Rectangle::setwidth(int w)
{
width=w;
}
int Rectangle::getArea()
{
return height*width;
}
int Rectangle::getCircumference()
{
return 2*(height+width);
}
Question 2- 2.cpp code:
#include#include "Rectangle.h"
using namespace std;
int main()
{
Rectangle r(8,5);
cout<<"The area is:"<
Rectangle.cpp 2 part code:
#ifndef _RECTANGLE_H
#define _RECTANGLE_H
class Rectangle
{
private:
int height;
int width;
public:
Rectangle(int h=1,int w=1);
Rectangle();
Rectangle (const Rectangle &other);
Rectangle & operator=(const Rectangle &other);
int getheight();
int getwidth();
void setheight(int h);
void setwidth(int w);
int getArea();
int getCircumference();
};
#endif
Score:98