The first chapter basic data and expressions

University is not heaven, but not an amusement park, you can be born again as hell.
Knowledge is important, learn to apply knowledge more important.
At the same time learn professional, daring to harvest what they really want.
Four years to concentrate on one thing, you will have more harvest (Python)

1.1 Overview
c language born in the 1970s, was originally written operating system, the lack of data type checking, code reuse is poor. Bell Labs in the 1980s were expanded to produce a c ++.
Programming language is a tool for people working in the computer command, it is an engineering language instruction system consisting of words and grammar rules. Way to solve computer problems can generally be abstract mathematical model. High-level language program is called the source. The computer can not directly identify the source, it must be translated into binary code to run in the machine.
Data Description: The description of the processed form of a computer data may be acceptable, such as integers, real numbers, characters, and other arrays. Data is the carrier of information, relying on information data is expressed. Data processing: data input, output, sorting, computing, storage, maintenance and other activities. Object data processing is to extract the required data elements to obtain useful information
[data description] Example 1-1: radius, perimeter, area represented by floating-point data.
Data processing the IPO: Enter the radius, perimeter to area calculation, the radius of the perimeter area of the output
codes are as follows:

#include <iostream>

using namespace std;

int main()
{
    double radius;  //定义半径
    double girth;   //周长
    double area;    //面积
    cin >> radius;
    girth = 3.1415926*2*radius;
    area = 3.1415926*radius*radius;
    cout << "半径为:" << radius << endl;
    cout << "周长为:" << girth  << endl;
    cout << "面积为:" << area << endl;
    return 0;

}

[Example 1-2] Method two: object-oriented programming methods.
When we use the object of thinking to consider the issue, the problem may be further abstracted to. Therefore, this type is called a "circle" of geometry, the most basic element is the radius. It determines the size of the circle, the circle is particularly distinguish A, B data base circle, the circle C and the like. Once the specific definition of a circle having a radius values, he will have a specific area and the perimeter.
"Circle" is a type. In the object-oriented approach, referred to as "class type" or "class", "round type" basic data "radius." Class of data called "attributes" or "data members."
zhonghuarenmingongheguoshandongshenghezeshichengwuxianmoumouzhenlibaokutongxue
data members have specific values later, you can calculate the area and perimeter. This calculation is implemented by the program code, and the "packaged" in a class, the class called "methods" or "member functions."

#include<iostream>

using namespace std;

class Circle
{
    double radius;
    public:
    void  Set_Radius(double r)
    {
        radius = r;
    }
    double Get_Radius()
    {
        return radius;
    }
    double Get_Girth()
    {
        return 3.14*2*radius;
    }
    double Get_Area()
    {
        return radius*radius*3.14;
    }

};
int main()
{
    Circle A,B;
    A.Set_Radius(6.23);
    B.Set_Radius(10.5);
    cout << A.Get_Radius() << '\t' << A.Get_Girth() << '\t' << A.Get_Area() << endl;
    cout << B.Get_Radius() << '\t' << B.Get_Girth() << '\t' << B.Get_Area() << endl;
}

Write your own Oh, wondering whether radius and r;

Compiler implementation:
translation in two ways: known as way of explanation, called

Guess you like

Origin blog.csdn.net/anyifan369/article/details/91345125