C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 6th, 2014, 11:40 AM
lizardqueen lizardqueen is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2014
Posts: 1 lizardqueen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 45 m 19 sec
Reputation Power: 0
Help with Cartesian class

I made a program witha Cartesian class. It's supposed to allow for user inputs of coordinates at run time, but it doesn't ask for any. How can I fix this? Also can anyone give me some tips on how to make an assignment function that allows me to set the values of coord1 to coord2?
Code:
#include <iostream>
#include <istream>
#include <ostream>

using namespace std;

class Cartesian
{
private:
double x;
double y;
public:
Cartesian( double= 0, double= 0);
friend istream& operator>>(istream&, Cartesian&);
friend ostream& operator<<(ostream&, const Cartesian&);
}
;

Cartesian::Cartesian(double a, double b)
{
    x=a;
    y=b;
}

istream& operator>>( istream& in, Cartesian& num)
{
    in >> num.x;
	in >> num.y;
    

return in;
}

ostream& operator<<( ostream& out, const Cartesian& num)
{
	cout << "(" << num.x << ", " << num.y << ")" << endl;

return out;
}

int main()
{
	Cartesian coord1, coord2;
	cout << "Please enter the first coordinates in the form x y: ";
	cin >> coord1;
	cout << "Please enter the second coordinates in the form x y: ";
	cin >> coord2;
	cout << coord1;
	cout << coord2;

	
	
	return 0;
}


Last edited by lizardqueen : April 6th, 2014 at 03:04 PM. Reason: I updated my code

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Help with Cartesian class


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap