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 03-Jun-2009, 19:27
NiCeBoY NiCeBoY is offline
New Member
 
Join Date: Jun 2009
Posts: 2
NiCeBoY is on a distinguished road

[urgent] Help Needed For Class In C++


Hello,
i am a newbie in programming..
i got an assignment which consist of 3 questions.
i was able to do first and second question but the third one i am getting some problems..

i am posting the code and question as image so as they don't appear on search engines as its for uni things...

The answer is a .cpp file. I modified the filename to .cpp.txt because the forum here does not allow upload of .cpp file.
can anyone correct the code and send it back to me please? i really newed them urgently...

only these part i think needs to modify:

first:
Quote:
// --------------------needs mods----

Circle_Shape(){};
Circle_Shape(Point c, double s){
centre = c;
size = s;
};

// ------------

second :
Quote:
// -----------------needs mods-------

Rec_Shape(){};
Rec_Shape(Point w, double s){
width = w;
size = s;
};

// ------------

Third
Quote:
cout << rect.area() << endl;
cout << rect.perimeter() << endl;
cout << circ.area() << endl;
cout << circ.perimeter() << endl;
I really need to get this working urgently...

Please when replying don't post the whole code directly on the forum...

send as attachment or just part which you modified...


Thank you very much in advance for your help...
Attached Images
File Type: jpg question3.JPG (61.5 KB, 10 views)
Attached Files
File Type: txt question3.cpp.txt (2.2 KB, 7 views)
  #2  
Old 03-Jun-2009, 19:42
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,373
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: [urgent] Help Needed For Class In C++


You obviously forgot to read the Guidelines
1) Nothing is ever urgent. Period.
2) We don't do homework for you. We help you do it yourself.
3) You need to ask a question. We can't help if we have no details.
4) If you are worried about uni and search engines, you shouldn't be posting. We aren't a secret evil society helping people get grades they don't deserve.
__________________

The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
  #3  
Old 03-Jun-2009, 22:54
NiCeBoY NiCeBoY is offline
New Member
 
Join Date: Jun 2009
Posts: 2
NiCeBoY is on a distinguished road

Re: [urgent] Help Needed For Class In C++


thanks for your help then..
  #4  
Old 04-Jun-2009, 06:39
Mexican Bob's Avatar
Mexican Bob Mexican Bob is offline
Regular Member
 
Join Date: Mar 2008
Location: Chicxulub, Yucatán
Posts: 342
Mexican Bob is a jewel in the roughMexican Bob is a jewel in the roughMexican Bob is a jewel in the roughMexican Bob is a jewel in the rough

Re: [urgent] Help Needed For Class In C++


Quote:
Originally Posted by NiCeBoY
Please when replying don't post the whole code directly on the forum...

Oops, my bad!

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

#include <cstring>
#include <cmath>

using namespace std;

const char* g_pt_sep = ", ";

class Point
{
public:
    Point() : m_x(0.0), m_y(0.0) {}
    Point(const double x, const double y) : m_x(x), m_y(y) {}
    Point(const Point& pt)
    {
	m_x = pt.m_x;
	m_y = pt.m_y;
    }
    Point& operator=(const Point& pt)
    {
	if(this != &pt)
	{
	    m_x = pt.m_x;
	    m_y = pt.m_y;
	}
	return *this;
    }
    bool operator!=(const Point& pt) const
    {
	bool inequality = false;
	if(m_x != pt.m_x || m_y != pt.m_y)
	{
	    inequality = true;
	}
	return inequality;
    }
    bool operator==(const Point& pt) const
    {
	bool equality = false;
	if(m_x == pt.m_x && m_y == pt.m_y)
	{
	    equality = true;
	}
	return equality;
    }
    friend ostream& operator<<(std::ostream& os, const Point& pt)
    {
	os << fixed << pt.m_x << g_pt_sep << pt.m_y;
	return os;
    }
    friend istream& operator>>(std::istream& is, Point& pt)
    {
	is >> fixed >> pt.m_x;
	is.ignore(strlen(g_pt_sep));
	is >> fixed >> pt.m_y;
	return is;
    }
    double distance(const Point& pt) const
    {
	// makes unsafe assumptions about x, y values
	double result = 0.0;
	if(this != &pt)
	{
	    result = sqrt(pow(pt.m_x - m_x, 2) + pow(pt.m_y - m_y, 2));
	}
	return result;
    }
protected:
    std::string m_sep;
private:
    double m_x;
    double m_y;
};

class Shape2D
{
public:
    virtual Point& getPoint() const = 0;
    virtual void setPoint(const Point& pt) = 0;
    virtual double area() const = 0;
    virtual double perimeter() const = 0;
    virtual ~Shape2D() {}
protected:
private:
    double m_size;
    Point* m_ppt; // center
};

class Rectangle : public Shape2D
{
public:
    Rectangle() : m_ppt(0) {}
    Rectangle(const Rectangle& rectangle) : Shape2D()
    {
	m_size = rectangle.m_size;
	if(m_ppt != NULL)
	{
	    delete m_ppt;
	}
	m_ppt = new Point(*rectangle.m_ppt);
    }	
    ~Rectangle()
    {
	if(m_ppt != NULL)
	{
	    delete m_ppt;
	}
    }
    Point& getPoint() const
    {
	return *m_ppt;
    }
    void setPoint(const Point& pt)
    {
	if(m_ppt != NULL)
	{
	    delete m_ppt;
	}
	m_ppt = new Point(pt);
    }
    double getSize() const
    {
	return m_size;
    }
    void setSize(const double size)
    {
	m_size = size; // is size height, length?
    }
    double area() const
    {
	double result = 0.0;
	return result; // not enough information to calculate
    } 
    double perimeter() const
    {
	double result = 0.0;
	return result; // not enough information to calculate
    } 
protected:
private:
    double m_size;
    Point* m_ppt; // center
};

class Circle : public Shape2D
{
public:
    Circle() : m_ppt(0) {}
    Circle(const Circle& circle) : Shape2D()
    {
	m_size = circle.m_size;
	if(m_ppt != NULL)
	{
	    delete m_ppt;
	}
	m_ppt = new Point(*circle.m_ppt);
    }	
    ~Circle()
    {
	if(m_ppt != NULL)
	{
	    delete m_ppt;
	}
    }
    Point& getPoint() const
    {
	return *m_ppt;
    }
    void setPoint(const Point& pt)
    {
	if(m_ppt != NULL)
	{
	    delete m_ppt;
	}
	m_ppt = new Point(pt);
    }
    double getSize() const
    {
	return m_size;
    }
    void setSize(const double size)
    {
	m_size = size; // is size radius, diameter?
    }
    double area() const
    {
	double result = 0.0;
	return result; // not enough information to calculate
    } 
    double perimeter() const
    {
	double result = 0.0;
	return result; // not enough information to calculate
    } 
protected:
private:
    double m_size;
    Point* m_ppt; // center
};

int main()
{
    Point p1(1, 2);
    Point p2;
    cout << "Enter a value for p2: ";
    cin >> p2;
    cout << "Distance between p1 (" << p1 << ") and p2 (" << p2 << ") = " << p1.distance(p2) << endl;

    Rectangle r;
    r.setSize(42);
    cout << "r.getSize() = " << r.getSize() << endl;

    Circle c;
    c.setSize(42);
    cout << "c.getSize() = " << c.getSize() << endl;


    return 0;
}



Output:

Code:
bash-3.2$ ./Shape2D Enter a value for p2: 2, 3 Distance between p1 (1.000000, 2.000000) and p2 (2.000000, 3.000000) = 1.414214 r.getSize() = 42.000000 c.getSize() = 42.000000


To blantantly request "help" and not allow the content to be displayed for all to see is probably against the general theme of this forum, which is to help those who visit it.

Your post seems like an excursion into the realm of academic dishonesty or, at least, probably some kind of violation of the rules enforced by the institution, which probably wants you to do your own work.

I don't believe that showing someone a working example--by itself--is an encouragement for an individual to be dishonest. I believe that we all need a body of working code to get us over the hump sometimes. Also, when the code is robust, it also encourages better programming practices be used, IMO.

If my post helps you understand some of what you're attempting to do so that you can better solve your own set of problems, fine by me...but all of this "sneaking around" seems, at the very least, devious.



MxB
 
 

Recent GIDBlogProblems with the Navy (Officers) 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
Program Needed: Perfect Number Program in C language koool_kid C Programming Language 13 22-Aug-2009 09:42
C++ games programmer needed (London, freelance contract) Nickdammit Computer Programming Advertisements & Offers 2 22-Dec-2008 14:01
Free 1st month / Free setup / No credit card needed...Plans start at 4.95 LarryIsaac Web Hosting Advertisements & Offers 0 11-Oct-2003 14:03

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

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


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