473,545 Members | 2,688 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Concepts of classes and objects in C/C++

how could I write a program that will declare a class point. The class
point has two private data members x and y of type float. The class
point has a parameterized constructor to initialize both the data
members i.e. x and y. The class point has a member function display()
that display the value of x and y. Create two objects p1 and p2 with
your desired data and display the values of x and y of p1 and p2. Now
create a third object p3 by using the expression p3=p1+p2 and display
the values of x and y of p3

Jul 14 '06 #1
31 1720
* at*******@hotma il.com:
how could I write a program that will declare a class point. The class
point has two private data members x and y of type float. The class
point has a parameterized constructor to initialize both the data
members i.e. x and y. The class point has a member function display()
that display the value of x and y. Create two objects p1 and p2 with
your desired data and display the values of x and y of p1 and p2. Now
create a third object p3 by using the expression p3=p1+p2 and display
the values of x and y of p3
Make a better effort of conceiling the homework nature of your question,
please.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 14 '06 #2
* Alf P. Steinbach:
* at*******@hotma il.com:
>how could I write a program that will declare a class point. The class
point has two private data members x and y of type float. The class
point has a parameterized constructor to initialize both the data
members i.e. x and y. The class point has a member function display()
that display the value of x and y. Create two objects p1 and p2 with
your desired data and display the values of x and y of p1 and p2. Now
create a third object p3 by using the expression p3=p1+p2 and display
the values of x and y of p3

Make a better effort of conceiling the homework nature of your question,
please.
Then I promise to try at least once to make a better effort at speling.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 14 '06 #3
Just a note: There is no language "C/C++". We say that because, among the
C-style languages, C and C++ have very different usages and strategies.
Posters are advised to always get clear about which one they mean, before
posting, for best results!

ttique63 wrote:
how could I write a program that will declare a class point.
By writing a program with lots of X and Y variables, and lots of unit tests.
The refactor the program, passing all the tests after the fewest possible
edits, over and over again until all Xs and Ys have migrated into the exact
kind of Point class that this program needs.

No lie; that's the most sophisticated way to do it. If you start by guessing
your program needs such-and-so Point class, and if you write the class
first, you will burden your design with decisions made without feedback.
The class
point has two private data members x and y of type float. The class
point has a parameterized constructor to initialize both the data
members i.e. x and y. The class point has a member function display()
that display the value of x and y. Create two objects p1 and p2 with
your desired data and display the values of x and y of p1 and p2. Now
create a third object p3 by using the expression p3=p1+p2 and display
the values of x and y of p3
Oh, back up a minute. This is homework, right?

Read your tutorial, write your Point class first - exactly like your
professor told you to - and don't mention _anything_ I posted here.

Then when you have taken a crack at your Point class, post it here and we
will gleefully review it. Possibly with an eye towards keeping you out of
trouble, instead of in it.

Posting your raw homework assignment, as given, is kind'a tacky. ;-)

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
Jul 14 '06 #4
<at*******@hotm ail.comwrote in message news:11******** **************@ h48g2000cwc.goo glegroups.com.. .
how could I write a program that will declare a class point. The class
point has two private data members x and y of type float. The class
point has a parameterized constructor to initialize both the data
members i.e. x and y. The class point has a member function display()
that display the value of x and y. Create two objects p1 and p2 with
your desired data and display the values of x and y of p1 and p2. Now
create a third object p3 by using the expression p3=p1+p2 and display
the values of x and y of p3
Ummm... by reading about classes in your textbook, then putting
what you learn into practice? In the time you spent typing the
message quoted above, you could have been done with your homework
assignment already.

I'll give you one hint to get you going: declaring a class called
"Point" is going to involve writing "class Point". The syntax is
in your textbook. Read about "classes" there, please.

Once you've written your program, if it doesn't work, come back
here and copy-and-paste your program and ask for help. You'll find
that folks here are willing to help you with your homework. NOT do
it for you, though! HELP you. That means, you have to do most of
the work yourself. Get cracking.
--
Cheers,
Robbie Hatley
East Tustin, CA, USA
lone wolf intj at pac bell dot net
(put "[usenet]" in subject to bypass spam filter)
http://home.pacbell.net/earnur/
Jul 14 '06 #5

Another tip when trying to get people to do your homework for you - try
to avoid using what is obviously the course module title as the subject
line !

Jul 14 '06 #6
how could I write a program that will declare a class point. The class
point has two private data members x and y of type float. The class
point has a parameterized constructor to initialize both the data
members i.e. x and y. The class point has a member function display()
that display the value of x and y. Create two objects p1 and p2 with
your desired data and display the values of x and y of p1 and p2. Now
create a third object p3 by using the expression p3=p1+p2 and display
the values of x and y of p3
class Point : public {

private float x, y;

public Point(float,flo at) : { x(arg1), x(arg2) }

public void Display() volatile
{
puts(FLOATING,x ,y);
}

};
void main(int)
{
Point p1 = { 5.6,4.3 };
Point p2 = { 2.1,8.9 };

p1->Display(void );
p2->Display(void );

Point p3 = p1 + p2;

p3->Display(void );
}

--

Frederick Gotham
Jul 14 '06 #7
"Frederick Gotham" <fg*******@SPAM .comwrote in message news:Tv******** ***********@new s.indigo.ie...
>
how could I write a program that will declare a class point. The class
point has two private data members x and y of type float. The class
point has a parameterized constructor to initialize both the data
members i.e. x and y. The class point has a member function display()
that display the value of x and y. Create two objects p1 and p2 with
your desired data and display the values of x and y of p1 and p2. Now
create a third object p3 by using the expression p3=p1+p2 and display
the values of x and y of p3

class Point : public {

private float x, y;

public Point(float,flo at) : { x(arg1), x(arg2) }

public void Display() volatile
{
puts(FLOATING,x ,y);
}

};
void main(int)
{
Point p1 = { 5.6,4.3 };
Point p2 = { 2.1,8.9 };

p1->Display(void );
p2->Display(void );

Point p3 = p1 + p2;

p3->Display(void );
}

--

Frederick Gotham
Tut-tut, my dear fellow; if you're going to do the OP's homework
for him, you should at least get him to slip you a ten spot. :-)

Two things I notice, though:

1. There's some errors in there. I'm assuming you put those
in there to force the OP to research the correct syntax for
himself, so I won't say what they are.
2. The subject line is all wrong, isn't it? Classes in C? No
such thing in C. Should read: "Concepts of classes and objects
in C++" People sure do like talking about that non-existant
language C/C++. (Actually, C/C++ would always be 1, regardless
of what's in C. But I digress.)

--
Cheers,
Robbie Hatley
East Tustin, CA, USA
lone wolf intj at pac bell dot net
(put "[usenet]" in subject to bypass spam filter)
http://home.pacbell.net/earnur/
Jul 14 '06 #8
In article <11************ **********@h48g 2000cwc.googleg roups.com>,
at*******@hotma il.com wrote:
how could I write a program that will declare a class point. The class
point has two private data members x and y of type float. The class
point has a parameterized constructor to initialize both the data
members i.e. x and y. The class point has a member function display()
that display the value of x and y. Create two objects p1 and p2 with
your desired data and display the values of x and y of p1 and p2. Now
create a third object p3 by using the expression p3=p1+p2 and display
the values of x and y of p3
First declare a class called Point.

Then give it two private data members x and y of type float.

Then write a parameterized constructor that initializes both data
members (i.e. x and y.)

Then write a member function called "display()" that displays the value
of x and y.

Now (this is the tricky part) create a non-member function operator+
that accepts two Points as parameters and returns a Point. Have it add
the x's and y's of the two points passed in.

After you do all of the above, create two objects p1 and p2 with some
data (whatever you desire) and call display on them.

Then create a third object p3 by using the expression p3 = p1 + p2 and
call display on it.
Jul 14 '06 #9

at*******@hotma il.com wrote:
how could I write a program that will declare a class point. The class
point has two private data members x and y of type float. The class
point has a parameterized constructor to initialize both the data
members i.e. x and y. The class point has a member function display()
that display the value of x and y. Create two objects p1 and p2 with
your desired data and display the values of x and y of p1 and p2. Now
create a third object p3 by using the expression p3=p1+p2 and display
the values of x and y of p3
Did you even bother trying to figure any of this out? This reads as if
you simply copied your homework assignment instructions verbatim. It
couldn't be more clear what you have to do here -- you have precise
instructions about how to design your program, and what steps to
follow.

Why don't you take a stab at this and come back if you get stuck. But
don't post any more questions until you have some code written. Many
people here would be happy to help, but you need to do some of the
work.

Jul 14 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

145
6191
by: David MacQuigg | last post by:
Playing with Prothon today, I am fascinated by the idea of eliminating classes in Python. I'm trying to figure out what fundamental benefit there is to having classes. Is all this complexity unecessary? Here is an example of a Python class with all three types of methods (instance, static, and class methods). # Example from Ch.23,...
6
1391
by: enki | last post by:
I had read that you should use classes to represent concepts. How does this work and what kind of concepts should be reresented as classes.
14
1293
by: Josema | last post by:
Hi to all, actually im a newbie in the OOP and i would like to know if this way of using clases its a best way (logical, and a good way) Lets imagine that i have a data base with departments (depid, depname) if i make the class public class department
0
15394
by: r035198x | last post by:
Overriding therefore allows you to use the same method name to refer to differently implemented methods. Here is an example using the famous shapes example. class Shape { public Shape() { } public double getArea() { return 5.0; }
2
1340
by: Joe | last post by:
I am trying to get a good understanding of these concepts and how they apply to code and classes (possibly different). As well as MSIL and Native Code (x86 assembly). To facilitate discussion consider the following code. ////////////////////////////////////////////////// // compiled with /clr ref class A {
20
2562
by: W Karas | last post by:
Would the fear factor for concepts be slightly reduced if, instead of: concept C<typename T> { typename T::S; int T::mem(); int nonmem(); };
5
6264
by: r035198x | last post by:
Setting up. Getting started To get started with java, one must download and install a version of Sun's JDK (Java Development Kit). The newest release at the time of writting this article is JDK 6 downloadable from http://java.sun.com/javase/downloads/index.jsp. I will be using JDK 5(update 8)
0
3882
by: r035198x | last post by:
Inheritance We have already covered one important concept of object-oriented programming, namely encapsulation, in the previous article. These articles are not articles on object oriented programming but on Java programming but I will cover all the important aspects of object oriented programming as Java has full support for object-oriented...
1
2112
by: Swathika | last post by:
Hi, Sometimes, you never get chance to learn 'Advanced Design Concepts and Real-time Scenarios' from institutes or through book-learning. But, in my blog, I have gathered some of the amazing Design concepts and practical scenarios in J2EE. Design Concepts:...
0
7943
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7456
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6022
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3490
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1919
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1044
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
743
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.