C / C ++中类和对象的概念 [英] Concepts of classes and objects in C/C++

查看:84
本文介绍了C / C ++中类和对象的概念的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能写一个会声明一个类点的程序。类

点有两个私有数据成员x和y,类型为float。类

点有一个参数化构造函数来初始化数据

成员,即x和y。类点有一个成员函数display()

,显示x和y的值。使用

创建两个对象p1和p2所需数据,并显示p1和p2的x和y值。现在

使用表达式p3 = p1 + p2创建第三个对象p3并显示

p3的x和y的值

解决方案

* at*******@hotmail.com


如何编写一个声明类点的程序。类

点有两个私有数据成员x和y,类型为float。类

点有一个参数化构造函数来初始化数据

成员,即x和y。类点有一个成员函数display()

,显示x和y的值。使用

创建两个对象p1和p2所需数据,并显示p1和p2的x和y值。现在

使用表达式p3 = p1 + p2创建第三个对象p3并显示

p3
的x和y值

更好地隐瞒你问题的作业性质,

please。


-

答:因为它弄乱了人们通常阅读文字的顺序。

问:为什么这么糟糕?

A:热门发布。

问:usenet和电子邮件中最烦人的事情是什么?


* Alf P. Steinbach:


* at*******@hotmail.com


>我怎么能写一个会声明一个类点的程序。类
点有两个类型为float的私有数据成员x和y。类
点有一个参数化构造函数来初始化数据成员,即x和y。类点有一个成员函数display()
,它显示x和y的值。使用
创建所需数据的两个对象p1和p2,并显示p1和p2的x和y值。现在通过使用表达式p3 = p1 + p2创建第三个对象p3并显示p3
的x和y的值

Make更好地隐瞒你问题的作业性质,

拜托。



然后我保证至少尝试一次以便更好地拼写。


-

答:因为它弄乱了人们通常阅读文字的顺序。

问:为什么这么糟糕?

A:热门帖子。

问:usenet和电子邮件中最烦人的事情是什么?


只是一个注释:没有语言 C / C ++" ;.我们之所以这么说是因为,在C / C语言中,C和C ++有着截然不同的用法和策略。

建议海报总是明白他们的意思

发布之前,以获得最佳效果!


ttique63写道:


我怎么能写一个会声明一个类点的程序。



编写一个包含大量X和Y变量以及大量单元测试的程序。

重构程序,通过所有经过尽可能少的编辑后再进行测试,一遍又一遍,直到所有的X和Y都迁移到这个程序需要的确切的Point类中。


没有谎言;这是最复杂的方式。如果你开始猜测

你的程序需要某种类型的Point类,如果你先写了这个类

,那么你的设计就会因为没有反馈而做出的决定。




点有两个私有数据成员x和y,类型为float。类

点有一个参数化构造函数来初始化数据

成员,即x和y。类点有一个成员函数display()

,显示x和y的值。使用

创建两个对象p1和p2所需数据,并显示p1和p2的x和y值。现在

使用表达式p3 = p1 + p2创建第三个对象p3并显示

p3
的x和y值

哦,等一下。这是作业,对吗?


阅读你的教程,先写一下你的Point课程 - 就像你的

教授告诉你的那样 - 并且没有提到_anything_我在这里发布了。


然后当你在Point课程上发表了一篇文章时,将它发布在这里,我们将会很高兴地回顾它。可能会着眼于让你免于麻烦,而不是在它里面。


如你所说,发布你的原始作业,是善意的俗气。 ;-)


-

Phlip
http://c2.com/cgi/wiki?ZeekLand < - 不是博客!!!


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

解决方案

* at*******@hotmail.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?


* Alf P. Steinbach:

* at*******@hotmail.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?


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!!!


这篇关于C / C ++中类和对象的概念的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆