SlideShare a Scribd company logo
3. In the program figurespointers we have a base class location and various derived classes:
circle, triangle, rectangle. Complete the implementation of the derived classes.
For marking purposes, run the program entering: circle(1,2,3), triangle(3,4,1,2,1) and
rectangle(5,6,3,4). Explain why this program does not work properly.
Change the classes (not main) so that the program runs properly and run the program with the
same data as before.
Declaration of Classes FigurePointers
This is the copy paste code for this code:
Declaration of Classes Figure Pointers:
/* File: figurepointers.h
*/
#ifndef FIGUREPOINTERS_H
#define FIGUREPOINTERS_H
#include <cmath>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class location {
private :
float x; // position of the figure
float y;
public :
void read(istream & in ) ;
void write(ostream & out ) const ;
virtual float area( void ) const ;
};
class circle : public location {
private :
float radius;
public :
void read(istream & in );
void write(ostream & out ) const ;
float area( void ) const ; // area of the figure;
};
class rectangle : public location {
private :
float side1, side2;
public :
void read(istream & in );
void write(ostream & out ) const ;
float area( void ) const ; // area of the figure;
};
class triangle : public rectangle {
private :
float angle;
public :
void read(istream & in );
void write(ostream & out ) const ;
float area( void ) const ; // area of the figure;
};
#endif /* FIGUREPOINTERS_H */
Implementation of Class FigurePointers:
/* File: figurepointers.cpp
Implementation of class figurepointers */
#include "figurepointers.h"
////////////////// implementation of location /////// ///////////
void location::read(istream & in)
{
cout <<"x coordinate: ";
in >> x;
cout <<"y coordinate: ";
in >> y;
}
float location::area( void ) const
{
return 0.0;
}
void location::write(ostream & out) const
{
out << "x coordinate: " << x << endl;
out << "y coordinate: " << y << endl;
out << "area = " << area() << endl;
}
////////////////// implementation of circle //////////////////
////////////////// implementation of triangle //////////////////
////////////////// implementation of rectangle //////////////////
Main Program Using Classes FigurePointers:
/* File: testfigurepointers.cpp
Application program using classes figurepointers
Programmer: your name Date: */
#include "figurepointers.h"
int main( void )
{
string type; // figure type
ofstream fout ("testfigurepointersout.txt");
location * p;
while ( true ) { // loop until break occurs
cout << endl << "Type of figure: "; cin >> type;
if (type == "circle") {
p = new circle;
p->read(cin);
fout << endl << "object is a circle" << endl;
p->write(fout);
delete p;
} else if (type == "triangle") {
p = new triangle;
p->read(cin);
fout << endl << "object is a triangle" << endl;
p->write(fout);
delete p;
} else if (type == "rectangle") {
p = new rectangle;
p->read(cin);
fout << endl << "object is a rectangle" << endl;
p->write(fout);
} else break ; // we are done entering data
}
fout.close();
return 0;
}
Declaration of Classes FigurePointers #endif /* FIGUREPOINTERSH */ Implementation of
Classes FigurePointers /* File: figurepointers. cpp Implementation of class figurepointers */
#include "figurepointers.h" void location:: read (istream & in) { cout < "x coordinate: "; in x ;
cout << " y coordinate: "; in y ; } float location:: area (void) const f return 0.0 ; } void location::
write (ostream & out) const { out "x coordinate: " < x x < endl ; out << "y coordinate: " < y <<
endl; out "area = " area () < endl } Main Program Using Classes FigurePointers
3- In the program figurespointers we have a base class location and va.pdf

More Related Content

PDF
Functions And Header Files In C++ | Bjarne stroustrup
PDF
Modify your solution for PLP04 to allow the user to choose the shape.pdf
DOCX
OOP project report cipher c++ .docx
PDF
I worte the code according to the requirement.And also I wrote the c.pdf
PDF
Need to revise working code below,A good design means the applicat.pdf
PDF
Opps manual final copy
PDF
OOPs manual final copy
PPTX
Structures - C Programming - Union - Basic Programming
Functions And Header Files In C++ | Bjarne stroustrup
Modify your solution for PLP04 to allow the user to choose the shape.pdf
OOP project report cipher c++ .docx
I worte the code according to the requirement.And also I wrote the c.pdf
Need to revise working code below,A good design means the applicat.pdf
Opps manual final copy
OOPs manual final copy
Structures - C Programming - Union - Basic Programming

Similar to 3- In the program figurespointers we have a base class location and va.pdf (20)

PPT
C++ tutorials
PDF
Module 1_Chapter 2_PPT (1)sasaddsdsds.pdf
PDF
Flight Landing Distance Study Using SAS
PDF
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
PDF
C++ L11-Polymorphism
PPTX
ppl unit 3.pptx ppl unit 3 usefull can understood
PPTX
Unit3 overview of_c_programming
PPT
Gdc09 Minigames
PDF
Example for Abstract Class and Interface.pdf
PPTX
visiblity and scope.pptx
PPT
Oops lecture 1
PDF
c++ lab manual
PDF
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdf
PPT
My programming final proj. (1)
PPTX
C++ Constructs.pptx
PDF
C and Data structure lab manual ECE (2).pdf
PDF
Using an Array include ltstdiohgt include ltmpih.pdf
PDF
Functionssssssssssssssssssssssssssss.pdf
PPT
Programming Fundamentals, C++, Object Oriented Programming
PPTX
Object Oriented Design and Programming Unit-04
C++ tutorials
Module 1_Chapter 2_PPT (1)sasaddsdsds.pdf
Flight Landing Distance Study Using SAS
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
C++ L11-Polymorphism
ppl unit 3.pptx ppl unit 3 usefull can understood
Unit3 overview of_c_programming
Gdc09 Minigames
Example for Abstract Class and Interface.pdf
visiblity and scope.pptx
Oops lecture 1
c++ lab manual
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdf
My programming final proj. (1)
C++ Constructs.pptx
C and Data structure lab manual ECE (2).pdf
Using an Array include ltstdiohgt include ltmpih.pdf
Functionssssssssssssssssssssssssssss.pdf
Programming Fundamentals, C++, Object Oriented Programming
Object Oriented Design and Programming Unit-04

More from atozshoppe (20)

PDF
4- -2 pts- Consider the ER schema for the MOVIES database as tollows-.pdf
PDF
4- A random variable X has a cumulative distribution function given by.pdf
PDF
4- A man named Paul has type A blood- His father is type AB and his mo.pdf
PDF
4- A density-dependent population grows according to dNt-dt-0-4Nt0-002.pdf
PDF
4- (8 points) The figure below shows the double Holliday junction mode.pdf
PDF
34- The Neurospora octad shown came from a cross between m+and mstrain.pdf
PDF
4- (10 points) Solve the following recurrence relation using tree meth.pdf
PDF
4) Using the area in figure- find the area to the right of Z-2- a) 0-8.pdf
PDF
33-34 will upvote Which of the following statements is correct- When a.pdf
PDF
4 Task 2- Understanding the Vulnerable Program The vulnerable program.pdf
PDF
4) A firm with unlimited funds must evaluate five projects- Projects 1.pdf
PDF
31- of all college students major in STEM (Science- Technology- Engine.pdf
PDF
37- D Genetic and genomic research can have D) 1 social and environm.pdf
PDF
36- The project management triangle is a simple communication model-.pdf
PDF
33- Helper T cells are differentiated into Th1 and Th2 according to a-.pdf
PDF
34-Explain differences between Lytic cycle and Lysogenic cycle- 35-.pdf
PDF
32- Which of these climographs shows an equatorial location- 33- Upwel.pdf
PDF
31- Saving Account Write a menu-driven program that allows the user to.pdf
PDF
3- What would be the most likely result if the domain of pRB that lets.pdf
PDF
3- What is the most dangerous greenhouse gas that has been released in.pdf
4- -2 pts- Consider the ER schema for the MOVIES database as tollows-.pdf
4- A random variable X has a cumulative distribution function given by.pdf
4- A man named Paul has type A blood- His father is type AB and his mo.pdf
4- A density-dependent population grows according to dNt-dt-0-4Nt0-002.pdf
4- (8 points) The figure below shows the double Holliday junction mode.pdf
34- The Neurospora octad shown came from a cross between m+and mstrain.pdf
4- (10 points) Solve the following recurrence relation using tree meth.pdf
4) Using the area in figure- find the area to the right of Z-2- a) 0-8.pdf
33-34 will upvote Which of the following statements is correct- When a.pdf
4 Task 2- Understanding the Vulnerable Program The vulnerable program.pdf
4) A firm with unlimited funds must evaluate five projects- Projects 1.pdf
31- of all college students major in STEM (Science- Technology- Engine.pdf
37- D Genetic and genomic research can have D) 1 social and environm.pdf
36- The project management triangle is a simple communication model-.pdf
33- Helper T cells are differentiated into Th1 and Th2 according to a-.pdf
34-Explain differences between Lytic cycle and Lysogenic cycle- 35-.pdf
32- Which of these climographs shows an equatorial location- 33- Upwel.pdf
31- Saving Account Write a menu-driven program that allows the user to.pdf
3- What would be the most likely result if the domain of pRB that lets.pdf
3- What is the most dangerous greenhouse gas that has been released in.pdf

Recently uploaded (20)

PPTX
History, Philosophy and sociology of education (1).pptx
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
Unit 4 Skeletal System.ppt.pptxopresentatiom
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PPTX
Digestion and Absorption of Carbohydrates, Proteina and Fats
PDF
Complications of Minimal Access Surgery at WLH
PDF
SOIL: Factor, Horizon, Process, Classification, Degradation, Conservation
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PDF
advance database management system book.pdf
PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
History, Philosophy and sociology of education (1).pptx
Weekly quiz Compilation Jan -July 25.pdf
Unit 4 Skeletal System.ppt.pptxopresentatiom
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Orientation - ARALprogram of Deped to the Parents.pptx
UNIT III MENTAL HEALTH NURSING ASSESSMENT
Digestion and Absorption of Carbohydrates, Proteina and Fats
Complications of Minimal Access Surgery at WLH
SOIL: Factor, Horizon, Process, Classification, Degradation, Conservation
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
advance database management system book.pdf
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
Chinmaya Tiranga quiz Grand Finale.pdf
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Paper A Mock Exam 9_ Attempt review.pdf.
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
A powerpoint presentation on the Revised K-10 Science Shaping Paper

3- In the program figurespointers we have a base class location and va.pdf

  • 1. 3. In the program figurespointers we have a base class location and various derived classes: circle, triangle, rectangle. Complete the implementation of the derived classes. For marking purposes, run the program entering: circle(1,2,3), triangle(3,4,1,2,1) and rectangle(5,6,3,4). Explain why this program does not work properly. Change the classes (not main) so that the program runs properly and run the program with the same data as before. Declaration of Classes FigurePointers This is the copy paste code for this code: Declaration of Classes Figure Pointers: /* File: figurepointers.h */ #ifndef FIGUREPOINTERS_H #define FIGUREPOINTERS_H #include <cmath> #include <iostream> #include <fstream> #include <string> using namespace std; class location { private : float x; // position of the figure float y; public : void read(istream & in ) ;
  • 2. void write(ostream & out ) const ; virtual float area( void ) const ; }; class circle : public location { private : float radius; public : void read(istream & in ); void write(ostream & out ) const ; float area( void ) const ; // area of the figure; }; class rectangle : public location { private : float side1, side2; public : void read(istream & in ); void write(ostream & out ) const ; float area( void ) const ; // area of the figure; }; class triangle : public rectangle { private : float angle; public :
  • 3. void read(istream & in ); void write(ostream & out ) const ; float area( void ) const ; // area of the figure; }; #endif /* FIGUREPOINTERS_H */ Implementation of Class FigurePointers: /* File: figurepointers.cpp Implementation of class figurepointers */ #include "figurepointers.h" ////////////////// implementation of location /////// /////////// void location::read(istream & in) { cout <<"x coordinate: "; in >> x; cout <<"y coordinate: "; in >> y; } float location::area( void ) const { return 0.0; } void location::write(ostream & out) const {
  • 4. out << "x coordinate: " << x << endl; out << "y coordinate: " << y << endl; out << "area = " << area() << endl; } ////////////////// implementation of circle ////////////////// ////////////////// implementation of triangle ////////////////// ////////////////// implementation of rectangle ////////////////// Main Program Using Classes FigurePointers: /* File: testfigurepointers.cpp Application program using classes figurepointers Programmer: your name Date: */ #include "figurepointers.h" int main( void ) { string type; // figure type ofstream fout ("testfigurepointersout.txt"); location * p; while ( true ) { // loop until break occurs cout << endl << "Type of figure: "; cin >> type; if (type == "circle") { p = new circle; p->read(cin); fout << endl << "object is a circle" << endl;
  • 5. p->write(fout); delete p; } else if (type == "triangle") { p = new triangle; p->read(cin); fout << endl << "object is a triangle" << endl; p->write(fout); delete p; } else if (type == "rectangle") { p = new rectangle; p->read(cin); fout << endl << "object is a rectangle" << endl; p->write(fout); } else break ; // we are done entering data } fout.close(); return 0; } Declaration of Classes FigurePointers #endif /* FIGUREPOINTERSH */ Implementation of Classes FigurePointers /* File: figurepointers. cpp Implementation of class figurepointers */ #include "figurepointers.h" void location:: read (istream & in) { cout < "x coordinate: "; in x ; cout << " y coordinate: "; in y ; } float location:: area (void) const f return 0.0 ; } void location:: write (ostream & out) const { out "x coordinate: " < x x < endl ; out << "y coordinate: " < y << endl; out "area = " area () < endl } Main Program Using Classes FigurePointers