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 26-Apr-2006, 02:45
iceman2006 iceman2006 is offline
New Member
 
Join Date: Apr 2006
Location: Hawaii
Posts: 21
iceman2006 is on a distinguished road

Math not processing entries properly


I am trying to use a derived class to:

1. enter an X and Y point, then print out the points
2. enter a radius, then print out the radius, diameter and circumference

As you probably can tell I am very new to programming. I looked at some related posts and tried to incorporate them into my code. However, I am missing a something. I need help with that "something".

When I run the program it apprears as if everything is working until the results for each of the outputs. It seems as if the math is not processing the entries properly.

Any help would be appreciated.

Thanks.

btw I am using DevC++.


CPP / C++ / C Code:
#include <iostream>
#include<string>
#include <cmath>

using namespace std;


// The pointType class declaration (base class)
class pointType
{
public:
	void setX(int xCoord);
	void setY(int yCoord);
             void setRadius(double radius);
	void print();
	int x;
	int y;
	double r;

};
// end of the PointType class declaration


// Beginning of the circleType class declaration (derived class)
class circleType : public pointType
{
public:
	double diameter();
	double circumference();
	void print();
	int x;
	int y;
	int r;

};
// end of the CircleType class declaration

// Beginning of the PointType constructor
void pointType::setX(int xCoord)
{
	x = xCoord;
}
void pointType::setY(int yCoord)
{
	y = yCoord;
}
void pointType::setRadius(double radius)
{
	r = radius;
}

void pointType::print()
{
	cout<<"\nThe X and Y coordinates are: "<< x <<","<< y <<"\n";
	cout<<"\nThe radius is: "<< r << "\n";

}
// End of the PointType constructor

//Beginning of the CircleType constructor
double circleType::diameter()
{
	return (2 * 2);
}
double circleType::circumference()
{
	return (r * 2 * 3.14);
}
void circleType::print()
{
	cout<<"\nThe diameter of the circle is: " << diameter() <<"\n";
	cout<<"\nThe circumference of the circle is: " << circumference() <<"\n";
}
int main()
{
	pointType pointInfo;
	circleType circleInfo;
	int yCoord;
	int xCoord;
	double radius;
	cout << "Enter the X coordinate: " <<"\n";
	cin >> xCoord;
	cout << "Enter the Y coordinate: " <<"\n";
	cin >> yCoord;
	cout << "Enter the radius of the circle: " <<"\n";
	cin >> radius;
	
    pointInfo.print();
    circleInfo.print(); 
    system("PAUSE");
	
	return 0;
}
Last edited by LuciWiz : 26-Apr-2006 at 02:48. Reason: Please insert your C++ code between [c++] & [/c++] tags
  #2  
Old 26-Apr-2006, 02:55
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 961
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough

Re: Math not processing entries properly


Where do you set the values of the object members? You acquired the input from the user, but never copied the values to the objects. Look at the print function: it uses some variables, which you must assign a value too; what member functions would you use to set the variables, and where?

Best regards,
Lucian
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
  #3  
Old 26-Apr-2006, 11:21
iceman2006 iceman2006 is offline
New Member
 
Join Date: Apr 2006
Location: Hawaii
Posts: 21
iceman2006 is on a distinguished road

Re: Math not processing entries properly


Thanks for the help. It seems to be working fine now.


CPP / C++ / C Code:
#include <iostream>
#include <cmath>

using namespace std;

// The pointType class declaration (base class)
class pointType
{
public:
    void setCoords(int xCoord, int yCoord);
	void print();
	int x;
	int y;
};
// end of the PointType class declaration

// Beginning of the circleType class declaration (derived class)
class circleType : public pointType
{
public:
	void setRadius(double radius);
    void print();
	double r;
    double radius();
    double diameter();
	double circumference();
};
// end of the CircleType class declaration

// Beginning of the PointType constructor
void pointType::setCoords(int xCoord, int yCoord)
{
     x = xCoord;
     y = yCoord;
}
void pointType::print()
{
	cout<<"\nThe X and Y coordinates are: "<< x <<","<< y <<"\n";
}
// End of the PointType constructor

//Beginning of the CircleType constructor
void circleType::setRadius(double radius)
{
     r = radius;
}
double circleType::diameter()
{
	return (r * 2);
}
double circleType::circumference()
{
	return (r * 2 * 3.14);
}
void circleType::print()
{
	cout<<"\nThe radius is: "<< r << "\n";
	cout<<"\nThe diameter of the circle is: " << diameter() <<"\n";
	cout<<"\nThe circumference of the circle is: " << circumference() <<"\n";
}
int main()
{
	pointType pointInfo;
	circleType circleInfo;
	int yCoord;
	int xCoord;
	double radius;
	cout << "Enter the X coordinate: " <<"\n";
	cin >> xCoord;
	cout << "Enter the Y coordinate: " <<"\n";
	cin >> yCoord;
	cout << "Enter the radius of the circle: " <<"\n";
	cin >> radius;
	pointInfo.setCoords(xCoord, yCoord);
	circleInfo.setRadius(radius);
	
    pointInfo.print();
    circleInfo.print(); 
    system("PAUSE");
	
	return 0;
}
Last edited by LuciWiz : 26-Apr-2006 at 11:28. Reason: Please insert your C++ code between [c++] & [/c++] tags
 
 

Recent GIDBlogWriting a book 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
[CONTEST?]Data Structure Test dsmith C Programming Language 2 06-Jun-2004 16:13

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

All times are GMT -6. The time now is 10:55.


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