D
Dan
Hi,
I would just like to know if the istream operator takes only one
parammeter(object) at a time (like z) ?
istream operator>>(istream& in, Shape &z)
Cause I keep getting error concerning the amount my operator has for bother
cin , cout operator<< and >>
thanks
Dan
#include <iostream>
#include<conio.h>
#include<cmath>
#include <algorithm>
using namespace std;
const double PI = 3.14159;
void Validate(float &);
int Validate_positive(float &);
float Abs(float Nbr)
{ if( Nbr >= 0 )
return Nbr;
else
return -Nbr; }
class Point {
public:
float x,y,c;
Point(float x1, float y1, float c1) {x = x1; y = y1; c = c1;}
Point() { x = y = c = 0;}
void get(float &u, float &v, float &w) {
u = x; v = y;w = c; }
};
class Shape {
public:
Point p;
Point p1;
Shape() { }
Shape(Point p) : p1(p)
{ }
void get(float &a, float &b, float &c) {
p1.get(a,b,c); }
virtual void Read(){};
virtual float GetVolume(){};
virtual void Display(){};
};
class Circle: public Shape
{
public:
Circle(){};
Circle(Point p, float r) : Shape(p) {radius = r; }
// void SetArea() {area= PI * radius * radius; }
float GetVolume(){ return PI * radius * radius;; }
friend istream& operator >> (istream& in, Shape& z);
friend ostream& operator << (ostream& out, const Shape* z);
void Read();
void display() {
float x,y,c;
get(x,y,c);
cout <<"This circle has center :"<<x<<","<<y<< endl;
cout<<" And color: " <<c<<" and radius :"<< radius <<endl; }
private:
float radius;
float x,y,c, z;
};
private:
Point p2;
Point p3;
float area;
};
void Circle::Read() {
cout<<" Enter the Center Point of the circle, X-Axis: " ;
cin>> x ;
cout<<endl;
cout<<" Enter the Center Point of the circle, Y-Axis: " ;
cin>> y ;
cout<<" Enter the Color of that point: " ;
cin>> c ;
cout<<" Enter the radius of the circle: " ;
cin>> z;
Point center(x,y,c);
Circle(center, z);
}
void menu();
int main()
{
menu();
getch();
return 0;
}
void menu()
{ char choice;
int i;
Shape* myShapes [10];
// Shape* ptr;
int countShapes = 0;
Circle circle;
do {
cout << endl << endl;
cout << " Shape Management System "<<endl;
cout << "============================================== "<<endl;
cout << " 1: Create a Circle "<<endl;
cout << " 2: Create a Triangle "<<endl;
cout << " 3: Create a Cylinder "<<endl;
cout << " 4: Display all Shapes "<<endl;
cout << " 5: Quit "<<endl;
cout << "============================================== "<<endl;
cout << " Your choice please: " ;
cin >> choice;
switch (choice)
{
case '1':
cin >> circle;
myShapes[countShapes++]= &circle;
break;
case '2': //ptr = new Triangle;
// myShapes[countShapes]->CreateShape();
// countShapes++;
break;
case '3': //ptr = new Cylinder;
// myShapes[countShapes]->CreateShape();
// countShapes++;
break;
case '4':
cout << " --- Displaying Objects --- " << endl;
for ( i=0; i < countShapes; i++)
cout << myShapes;
break;
case '5': cout<<"Thank you for having used this system, Bye Bye!!!" ;
break;
default: cout<<"Error: Invalid option, Please try again" <<endl;
}
// myShapes[countShapes] = ptr;
}while ( (choice != '5') ) ;
}
istream operator>>(istream& in, Shape &z)
{
z.Read();
return in;
}
ostream operator <<(ostream& out, Shape *z)
{
z->Display();
return out;
}
I would just like to know if the istream operator takes only one
parammeter(object) at a time (like z) ?
istream operator>>(istream& in, Shape &z)
Cause I keep getting error concerning the amount my operator has for bother
cin , cout operator<< and >>
thanks
Dan
#include <iostream>
#include<conio.h>
#include<cmath>
#include <algorithm>
using namespace std;
const double PI = 3.14159;
void Validate(float &);
int Validate_positive(float &);
float Abs(float Nbr)
{ if( Nbr >= 0 )
return Nbr;
else
return -Nbr; }
class Point {
public:
float x,y,c;
Point(float x1, float y1, float c1) {x = x1; y = y1; c = c1;}
Point() { x = y = c = 0;}
void get(float &u, float &v, float &w) {
u = x; v = y;w = c; }
};
class Shape {
public:
Point p;
Point p1;
Shape() { }
Shape(Point p) : p1(p)
{ }
void get(float &a, float &b, float &c) {
p1.get(a,b,c); }
virtual void Read(){};
virtual float GetVolume(){};
virtual void Display(){};
};
class Circle: public Shape
{
public:
Circle(){};
Circle(Point p, float r) : Shape(p) {radius = r; }
// void SetArea() {area= PI * radius * radius; }
float GetVolume(){ return PI * radius * radius;; }
friend istream& operator >> (istream& in, Shape& z);
friend ostream& operator << (ostream& out, const Shape* z);
void Read();
void display() {
float x,y,c;
get(x,y,c);
cout <<"This circle has center :"<<x<<","<<y<< endl;
cout<<" And color: " <<c<<" and radius :"<< radius <<endl; }
private:
float radius;
float x,y,c, z;
};
private:
Point p2;
Point p3;
float area;
};
void Circle::Read() {
cout<<" Enter the Center Point of the circle, X-Axis: " ;
cin>> x ;
cout<<endl;
cout<<" Enter the Center Point of the circle, Y-Axis: " ;
cin>> y ;
cout<<" Enter the Color of that point: " ;
cin>> c ;
cout<<" Enter the radius of the circle: " ;
cin>> z;
Point center(x,y,c);
Circle(center, z);
}
void menu();
int main()
{
menu();
getch();
return 0;
}
void menu()
{ char choice;
int i;
Shape* myShapes [10];
// Shape* ptr;
int countShapes = 0;
Circle circle;
do {
cout << endl << endl;
cout << " Shape Management System "<<endl;
cout << "============================================== "<<endl;
cout << " 1: Create a Circle "<<endl;
cout << " 2: Create a Triangle "<<endl;
cout << " 3: Create a Cylinder "<<endl;
cout << " 4: Display all Shapes "<<endl;
cout << " 5: Quit "<<endl;
cout << "============================================== "<<endl;
cout << " Your choice please: " ;
cin >> choice;
switch (choice)
{
case '1':
cin >> circle;
myShapes[countShapes++]= &circle;
break;
case '2': //ptr = new Triangle;
// myShapes[countShapes]->CreateShape();
// countShapes++;
break;
case '3': //ptr = new Cylinder;
// myShapes[countShapes]->CreateShape();
// countShapes++;
break;
case '4':
cout << " --- Displaying Objects --- " << endl;
for ( i=0; i < countShapes; i++)
cout << myShapes;
break;
case '5': cout<<"Thank you for having used this system, Bye Bye!!!" ;
break;
default: cout<<"Error: Invalid option, Please try again" <<endl;
}
// myShapes[countShapes] = ptr;
}while ( (choice != '5') ) ;
}
istream operator>>(istream& in, Shape &z)
{
z.Read();
return in;
}
ostream operator <<(ostream& out, Shape *z)
{
z->Display();
return out;
}