GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 21-Apr-2009, 13:30
missy missy is offline
Awaiting Email Confirmation
 
Join Date: Mar 2009
Posts: 9
missy is on a distinguished road

Help with C++ class


a. a point in the x-y plane is represented by its x-coordinate and y-coordinate. Design a class, pointType, that can store and process a point in the x-y plane.

b. Every circle has a center and a radius. Given the radius we determine the circles area and circumference. Given the center we can determine its position in the x-y plane. The center of a circle is a point in the x-y plane. Design a class, circleType, that can store the radius and center of the circle. Because the center is a point in the x-y plane, and you designed the class to capture the properties of a point in Programming exercise a, you must derive the class circleType from the class pointType. You should be able to perform the usual operations on the circle, such as setting the radius, printing the radius, calulating and printing the area and circumference, and carrying out the usual operations on the center. Also write a program to test various operations on a circle.
Any help is appreciated





CPP / C++ / C Code:
#include <iostream>
using namespace std;

class pointType 
{
public:
	pointType(double x = 0, double y = 0) 
	{
		xCoordinate = x;
		yCoordinate = y;
	}
	double getX() {return xCoordinate;}
	double getY() {return yCoordinate;}
protected:
	double xCoordinate, yCoordinate;
};

class circleType: public pointType
{
	double rad;
	
	public:
circleType(double r, double x, double y): pointType(x, y)
{
	rad = r;
}
void print();


};

int main()
{
	circleType cir(1, 2, 3);
	double x, y, z;
char a, b, c;
cout<< "Enter circle radius: " <<endl;
cin >> x;
cout<<"Enter center point coordinates: " <<endl;
cin>> a >> y >> b >> z >> c;

 
cout << "Circle 1: ";
cir.print();
//cout << endl;
	
	
	
	//circleType c(1, 2, 3);
	//cout << "Circle:  " << endl;
	//cin >> 1 >> 2 >> 3;
	//cout << endl;
	return 0;
}
  #2  
Old 21-Apr-2009, 15:09
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 713
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: Help with C++ class


Is there a question that you have?
  #3  
Old 21-Apr-2009, 15:14
ocicat ocicat is offline
Regular Member
 
Join Date: May 2008
Posts: 580
ocicat is a jewel in the roughocicat is a jewel in the rough

Re: Help with C++ class


Quote:
Originally Posted by missy
You should be able to perform the usual operations on the circle, such as setting the radius, printing the radius, calulating and printing the area and circumference, and carrying out the usual operations on the center.
Quote:
CPP / C++ / C Code:
class pointType 
{
public:
	pointType(double x = 0, double y = 0) 
	{
		xCoordinate = x;
		yCoordinate = y;
	}
	double getX() {return xCoordinate;}
	double getY() {return yCoordinate;}
protected:
	double xCoordinate, yCoordinate;
};

class circleType: public pointType
{
	double rad;
	
	public:
circleType(double r, double x, double y): pointType(x, y)
{
	rad = r;
}
void print();


};
Okay, you have the beginnings. That's great. Now is the time to refine & flesh out the code to meet the remaining requirements. So, consider the following points as a start:
  • Your circleType constructor takes three parameters & you save one as the radius as a member within this derived class. How can you pass the other two parameters to the base class?
  • You have provided the prototype for a print() member function. What code should be enclosed?
  • Thirdly (for now...), do you know the formula for determining the area of a circle?
 
 

Recent GIDBlogProgramming ebook direct download available by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Returning a Struct to a separate class usmsci C++ Forum 9 07-Feb-2007 09:34
Hard drive/CPU Diagnoses Issues binarybug Computer Hardware Forum 1 22-Jan-2007 20:23
Box Class, need help again :( TransformedBG C++ Forum 7 13-Nov-2006 16:11
C++ class -- Please help vnca_1 C++ Forum 3 14-Jun-2006 13:31
a tester class and then some. postage Java Forum 1 06-May-2006 16:48

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 16:07.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.