Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Now I nearly finished my C++ lab but I am getting tons of bugs in my code. Pleas

ID: 666080 • Letter: N

Question

Now I nearly finished my C++ lab but I am getting tons of bugs in my code. Please help me by pointing out all the mistakes I made... Thanks a lot.

lab requirements:

http://www.csit.parkland.edu/~dbock/Class/csc125/Labs/Lab8.html

my code:

#include <iostream>
#include <cstdlib>

using namespace std;

class Shape
{
protected:
float base;
float height;
float width;
float radius;
float area;
public:
void getlength();
void printarea(int);

class Triangle : public Shape
{
void getlength()
{
cout << "Input Your Triangle's base length ";
cin >> base;
cout << "Input Your Triangle's height length ";
cin >> height;
}
void printarea()
{
area = 1/2 * base * height;
cout << "Your triangle's area is "<< area <<" ";
}
};
class Rectangle : public Shape
{
void getlength()
{
cout << "Input Your Rectangle's width length ";
cin >> width;
cout << "Input Your Rectangle's height length ";
cin >> height;
}
void printarea()
{
area = width * height;
cout << "Your triangle's area is "<< area <<" ";
}
};
class Circle : public Shape
{
void getlength()
{
cout << "Input Your Rectangle's width length ";
cin >> radius;
}
void printarea()
{
area = 3.14 *radius*radius;
cout << "Your triangle's area is "<< area <<" ";
}
};

void main()
{
Triangle tri;
Rectangle rec;
Circle cir;

cout<<" Area of Different Shapes:";
cout<<" 1. Area of a Triangle";
cout<<" 2. Area of a Rectangle";
cout<<" 3. Area of a Circle";
cout<<" 4. Exit";
cout<<" Enter your choice:";
cin>>choice;

switch(choice)
{
case 1:
tri.getlength();
tri.printarea();
break;
case 2:
rec.getlength();
rec.printarea();
break;
case 3:
cir.getlength();
cir.printarea();
case 4:
system("PAUSE");
return 0;
break;
default:
cout<<"Enter your choice of shape (1-4)";
break;
}
}

Explanation / Answer

#include<iostream.h>
#include<conio.h>
#include<process.h>

class shape
{
protected:
double b;
double h;
public:
shape(double b1,double h1)
{
b=b1;
h=h1;
}

shape(double b1)

{

b=b1;

}
virtualvoid disp_area()=0;
};

class triangle :public shape
{
public:
triangle(double b1, double h1):shape(b1,h1)
{
}
void disp_area();
};

class rectangle:public shape
{
public:
rectangle(double b1,double h1):shape(b1,h1)
{
}
void disp_area();
};

class rectangle:public shape
{
public:
circle(double ra1,):shape(ra1)
{
}
void disp_area();
};

void triangle::disp_area()
{
double a1;
a1=(b*h)*1/2;
cout<<" THE AREA OF TRIANGLE IS :"<<a1;
getch();
}

void rectangle::disp_area()
{
double a1;
a1=b*h;
cout<<" THE AREA OF RECTANGLE IS :"<<a1;
getch();
}

void circle::disp_area()
{
double a1;
a1=3.14*ra1;
cout<<" THE AREA OF CIRCLE IS :"<<a1;
getch();

}

main()
{
double b1,h1;
clrscr();
cout<<" PLEASE ENTER THE TRIANGLE DETAILS ";
cout<<"BASE = ";
cin>>b1;
cout<<" HYPOTENUSE = ";
cin>>h1;
triangle t1(b1,h1);
cout<<" PLEASE ENTER THE RECTANGLE DETAILS ";
cout<<" LENGTH = ";
cin>>b1;
cout<<" BREADTH = ";
cin>>h1;
rectangle r1(b1,h1);

cout<<" PLEASE ENTER THE circle DETAILS ";
cout<<" RADIUS = ";
cin>>ra1;

circle c1(ra1);

shape *list[3];
list[0]=&t1;
list[1]=&r1;

list[2] = &c1;

while(1)
{
clrscr();
cout<<" ------------MENU------------";
cout<<" 1. TRIANGLE AREA";
cout<<" 2. RECTANGLE AREA";

cout<<" 2. CIRCLE AREA";
cout<<" 4. EXIT";
cout<<" ENTER YOUR CHOICE :";
int ans;
cin>>ans;
if(ans ==1)
{
list[0]->disp_area();
}
elseif(ans==2)
{
list[1]->disp_area();
}
elseif(ans==3)

{
list[2]->disp_area();
}

elseif(ans==4)
exit(1);
else
{
cout<<" INVALID CHOICE";
getch();
continue;

}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote