当前位置:网站首页>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; }
};
边栏推荐
- 基础架构之日志管理平台及钉钉&邮件告警通知
- String转为long 类型报错原因:要转为long必须是int、double、float型[通俗易懂]
- Recommended super easy-to-use mobile screen recording software
- 围绕新市民金融聚焦差异化产品设计、智能技术提效及素养教育
- 【LeetCode】 贴纸拼词(动态规划)
- Pointers and arrays (7)
- 在 SwiftUI 视图中打开 URL 的若干方法
- Floating point data type in C language (did you learn to waste it)
- 数字化转型安全问题频发,山石网科助力数字政府建设
- Error reason for converting string to long type: to convert to long type, it must be int, double, float type [easy to understand]
猜你喜欢
![[ecmascript6] async and await](/img/3c/c7de42ad572dc95b188243c02dd228.png)
[ecmascript6] async and await

9、 Uni popup usage popup effect at the bottom of the drop-down box

These three online PS tools should be tried

Redis redis use in jedis

基于 MinIO 对象存储保障 Rancher 数据

国产数据库的红利还能“吃”多久?

ScottPlot入门教程:获取和显示鼠标处的数值

一些企业数据平台建设的思考

BGP experiment

2022 high altitude installation, maintenance, removal of examination question bank and online simulated examination
随机推荐
SwiftUI 布局 —— 对齐
Swiftui layout - size (top)
Factory mode and constructor mode
JS instantiation method
Another way of understanding the essence of Hamming code
BGP experiment
多线程顺序运行有几种方法?
Getting started with scottplot tutorial: getting and displaying values at the mouse
2022 melting welding and thermal cutting examination questions and online simulation examination
Unittest executes runtestcase prompt <_ io. Textiowrapper name= '< stderr>' mode=W encoding=UTF-8 > solution
Swiftui layout - alignment
Bulk Rename Utility
&0xffffffff(0x08)
&0xffffffff(0x08)
基础架构之日志管理平台及钉钉&邮件告警通知
多商户商城系统功能拆解17讲-平台端订单列表
C语言库函数getchar()怎么使用
围绕新市民金融聚焦差异化产品设计、智能技术提效及素养教育
468产品策划与推广方案(150份)
How does core data save data in SQLite