当前位置:网站首页>The third pre class exercise
The third pre class exercise
2022-07-28 14:46:00 【Qing Ankang】
Catalog
One 、 Single topic selection
2-1
Given the following class declaration , Which member function may change the member variable data?(D)
class A {
public:
void f1 (int d);
void f2 (const int &d);
void f3 (int d) const;
private:
int data;
};
A.f1
B.f2
C.f3
D.f1 and f2
2-2
In the following keywords , Used to describe the public members of a class is (A ).
A.public
B.private
C.protected
D.friend
2-3
The following incorrect statements about classes and objects are ( C).
A. Object is an instance of a class
B. Any object can only belong to a specific class
C. A class can only have one object
D. The relationship between classes and objects is similar to that between data types and variables
2-4
The default access property of class members is :(A)
A.private
B.protected
C.public
D. None of the above answers is true
2-5
In object-oriented software systems , A construction of communication between objects of different classes is called ___D____.
A. attribute
B. encapsulation
C. class
D. news
Two 、 Completion
1.(6 branch )A class is a user-defined type A class consists of a set of members. The most common kinds of members are data members and member functions A class is a namespace containing its members.
2.(6 branch )C++ classes are a tool for creating new types that can be used as conveniently as the built-in types The fundamental idea in defining a new type is to separate the incidental details of the implementation(e.g., the layout of the data used to store an object of the type) from the properties essential to the correct use of it (e.g., the complete list of functions that can access the data). Such a separation is best expressed by channeling all uses of the data structure and its internal housekeeping routines through a specific interface
3、 ... and 、 Function questions
6-1 Design a project called Rectangle Rectangle class (C++ set function )
fraction 10
author Zhang Dehui
Company Xi'an University of Posts and Telecommunications
Design a project called Rectangle Rectangle class , This class includes : Two are called width and height Of double Data fields , They represent the width and height of the rectangle, respectively . One for width and height The function that sets the initial value set( ); A group called getArea( ) Function that returns the area of a rectangle ; A group called getPerimeter( ) The function of returns the perimeter of the rectangle . Please implement this class .
Class called :
Rectangle
Sample referee test procedure :
Here is an example of a function being called for testing . for example :
#include
using namespace std;
// The code you submit will be embedded here
int main()
{
double m,n;
cin>>m;
cin>>n;
Rectangle a;
a.set(m,n);
cout<<a.getArea()<<endl;
cout<<a.getPerimeter()<<endl;
return 0;
}
sample input :
3.5 35.9
sample output :
125.65
78.8
class Rectangle
{
private:
double width;
double height;
public:
void set(double m,double n)
{
width=m;
height=n;
}
double getArea()
{
double area;
area=width*height;
return area;
}
double getPerimeter()
{
double perimeter;
perimeter=2*(width+height);
return perimeter;
}
};
6-2 Point Class declaration and Implementation
fraction 10
author Li Tingyuan
Company China Academy of Civil Aviation
Define a Point class , Represents a point on the plane , Its abscissa and ordinate are respectively in x and y Express , Design Point class , Implement and test this class .
Enter the coordinates of the two points in the main function , Calculate and output the distance between two points . Please implement according to the main function Point class .
Sample referee test procedure :
#include
#include
#include
using namespace std;
// Your code will be embedded here
int main()
{
Point p1, p2;
double x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
p1.setX(x1);
p1.setY(y1);
p2.setX(x2);
p2.setY(y2);
double x = p1.getX() - p2.getX();
double y = p1.getY() - p2.getY();
double len = sqrt(x * x + y * y);
cout << fixed << setprecision(2) << len << endl;
return 0;
}
sample input :
0 0 3 3
sample output :
4.24
class Point
{
private:
int x, y;
public:
void setX(double x1) {
x = x1; }
void setY(double y1) {
y = y1; }
double getX() {
return x; }
double getY() {
return y; }
};
边栏推荐
- 国产数据库的红利还能“吃”多久?
- Thrift 序列化协议浅析
- 2022高处安装、维护、拆除考试题库及在线模拟考试
- I am using a blog creation tool
- String转为long 类型报错原因:要转为long必须是int、double、float型[通俗易懂]
- Metersphere -- Open Source continuous testing platform
- C语言库函数getchar()怎么使用
- Chi square distribution and gamma function
- It's so hot that solar power can't take off? Hello, head
- Brief introduction of diversity technology
猜你喜欢

使用Weka与Excel进行简单的数据分析

The method of implementing simple student achievement management system with C language

2022 high altitude installation, maintenance, removal of examination question bank and online simulated examination
Excel VBA 开发过程中遇到的一些问题,解决方案,持续更新
C# 获取当前路径7种方法

@DS('slave') 多数据源兼容事务问题解决方案

58子站安居,经纪人营销管理平台登录接口加密逆向

数字化转型安全问题频发,山石网科助力数字政府建设

Career planning of Software Test Engineer

TDengine 助力西门子轻量级数字化解决方案
随机推荐
文件批量重命名工具Bulk Rename Utility
【七夕】七夕孤寡小青蛙究极版?七夕节最终章!
js的实例化方式
Focus on differentiated product design, intelligent technology efficiency improvement and literacy education around new citizen Finance
Qt中QTableView设置分页显示的三种方法[通俗易懂]
为什么jq的匿名函数 外部可以访问到里面的方法
Ability to add class @published for custom attribute wrapper types
[leetcode] 1331. Array sequence number conversion
How to perform batch operations in core data
2022高处安装、维护、拆除考试题库及在线模拟考试
2022 melting welding and thermal cutting examination questions and online simulation examination
ZABBIX distributed
58 sub station Anju, broker marketing management platform login interface encryption reverse
C# 获取当前路径7种方法
Use of formdata object, VAR formdata=new formdata()
pix2pix
10、 Timestamp
Several methods of opening URL in swiftui view
基于 MinIO 对象存储保障 Rancher 数据
力扣解法汇总1331-数组序号转换