C ++ quick start

zhaozj2021-02-17  54

The first C introduction catalog 1, introduction 1.1, why should you program? 1.2, what is C and OOP? 1.3, what is the programming? 2, the first program 2.2, run a C program 2.2, C program structure 2.3, note 2.4, library 2.5, function 2.6, stream 2.7, return 3, digital system 3.1, decimal 3.2, binary 3.3, sixteen into 4, practice 4.1, practice 14.2, practice 24.3, practice 35, now what? 5.1 Excellent programming site 5.2, excellent programming book body 1, introduction 1.1, why to program? Everyone has the reason why his own programming, but I can tell you that the program is one of the best ways to understand the in-depth understanding of computers and computer technology. Learning programming allows you to know why your computer and computer programs work in this way. Programming will make you understand how hard it is. 1. 2, what is C and OOP? C is an expansion version of C. C is born in Bell laboratory in 1978. The purpose of developing C is to create a simple language that can be used on a variety of platforms (simpler than assembly and machine code ...). Later, C was expanded as C in the 1980s to create an object-oriented language. O (Bject, Object) O (RIENTED, Based on) P (Rogramming, Programming) is a programming method for constructing a program. The type identifier is used to distinguish the main function and the subsequent class. OOP is in the method, C makes it possible to prepare a very complex graphics application environment (such as Windows, Macintosh ...) on the implementation. 1. 3, what do you need for programming? I think you need a computer and a compiler to start your journey, and you still need some catalysts that prompted your advancement - curiosity and a lot of time. I guess (!?) You have a computer. You can also find a variety of free compilers on Borland's website (see 3.1). You have a curiosity but not to sit down and study, then you just have time to read. There is a good C book to help you very busy (and it is also beneficial to your eyes). Need to remember: No guide, books, procedures, or courses can make you a programmer within 5 days. Only you can make you a programmer. Any compiler cannot write a complete program for you. The program is written. 2, the first program 2.1, run a C program A C program only after the compilation and link can be executed or run on the computer. A variety of compilers automatically help you complete this work. What is the compiler? The compiler is a program that translates C code into a machine language. The machine language is a language composed of 0 and 1, which is the "native language" of the computer. A typical C program is called source code, and the corresponding code is called a target code. Before execution of the target code, it must be linked to the code (such as the library contained in the program) in the program. Thus, the program after compilation and link is called an executable. Finally, this program is executed by the system. The execution output results are displayed in the window. 2.2, C Program Structure All C programs contain statements (commands) with command computers.

Here is a simple C program sample: / * from code.box.sk we own you program * / # include

INT main () {cout << "We own you"; // First statement RETURN (0); // Second statement}

Run this program, it should be displayed:

We own you

Thus, a simple C program structure is:

*********************************************************** *** * / * Note: Program name and destination * Your name, date, etc. * / * * * #include * * int main () * {* statements; // Note * Return (0) ; *} ******************************************************** *******

Below we will make a more in-depth understanding of this structure. 2.3, annotation comments are used to explain the contents of the program to the reader, and the computer will ignore them. "/ *" And "* /" are used to identify the beginning and end of multi-line comments. "//" is also used in comments, "//" all characters will be treated as an annotation and ignore (one line). The vast majority of newcomers will think that comments are only wasted. Sorry, this view is wrong. Comments are very important because it makes your code are appreciated by other programmers and makes it easy to improve procedures and error corrections. A few months later, when you try to explain the one hundred code you wrote, you will have a more profound understanding. 2. 4, the library looks again to the example example mentioned. After the comment started:

#include

This line briefly tells the computer program that requires the iostream library, so it should be included. The library is a set of program that can be used to make a variety of operations in the user program. iostream is a library (also called header file) for performing an input / output (I / O) task. In Code.box.sk, you can find a C library written by the un commercialized purposes prepared by the desperate use of experts. 2. 5, the function next line is:

int main ()

This is the declaration section of the function. The function is a collection of some column statements used to complete a task. Function declarations include function names and functions return values. As indicated by the statement, the main function returns an integer value via return (0). Similarly, all documents must return to an integer value. Obviously, the function (here is the main function) ends with curly brackets. "{" And "}" represent the beginning and end of the function. We will explore the function more inward in the future. 2.6, what is the stream? In C , the input / output device is called a stream. Cout (I used above) is a C (ONSOLE, console) OUT (PUT, output) stream, and the send (insert) operator is used to send "We own you" data to the stream. In the first statement:

Cout << "we own you";

A string is formed with a character in the "<<" operator. When the program is running, "We own you" is sent to the console output device. Yes, it is also called computer screen. ! Note: C is case sensitive. That is to say, COUT and COUT are different. 2.7, return the second statement is: return (0);

Used to end the program to run and send the return value 0 to the computer. "0" representative program ends normally. ! Note: The statement is used to end. The semicolon in C means the end of the statement. 3. Data system 3.1, a digital system having a decimal base is 10. Use 10 numbers: 0 to 9. Any number of weighted 0 is equal to 1. For example: 5 Weighted 0 = 1. Number of base 10 and weighted represented: 2600: 2 * (10 Weighted 3) 6 * (10 Weighted 2) 33: 3 * (10 Weighted 1) 3 * (10 Weighted 0) 3.2, binary base is 2 Digital System. Use 2 numbers: 0 and 1. Working principle is the same as the decimal, but the base is 2 instead of 10. For example: 110: 1 * (2 Weighted 2) 1 * (2 Weighted 1) = 6 (decimal) 3.3, the hexadecimal base is 16 digital system. Use 16 numbers: 0 to 9 and "a" to "f". Working principle is the same as the decimal, but the base is 16 instead of 10. For example: 1b: 1 * (16 weighted 1) b * (16 weighted 0) = 27 (decimal) 4. Exercise 4.1, run a compiler and install it, then enter the above sample program and run. Please pay attention to the syntax structure! 4.2, programming does not look at the sample program, you have a program that you can display your name. Please note that you don't look at the sample program, which is very good for you. 4.3, conversion binary conversion into ten credits: 110101,001101,10101110 decimal conversion into hexadecimal: 234, 324, 19394 hexadecimal conversion into binary: 2F, 1B3, 234, 1255. What is it now? 5.1, excellent programming site http://code.box.sk -> content enrich http://www.borland.com -> Free, Shared and Commercial Compiler http://www.cprogramming.com -> Some Original Tutshtp://www.planet-source-code.com -> Source code is extremely rich 5.2, excellent programming book - "a guide to programming in C (C Program Guide) My A book about C (from there "-" C-HOW TO Program (C program design) is one of the best books for C programming. Both of the programmers for all levels. - "Online book you can find many online books on Code.box.sk. Think In C (C Programming Thoughts) should be the best one, must read!

The second I / O and Variable Contents 1, Introduction 5.3, what is this? 5.4, ​​what need to be prepared? 2, console output 2.1, ignore character 2.2, basic operation 3, variables and constant 3.1, what is a variable? 3.2, Data Type 3.3, Plastic (INT) and Long Plastic (Long) 3.4, Double Floating Point (Double) 3.5, Character Type (CHAR) 3.6, Constant 4, Console Input 4.1, how to do it? 4.2, sample program 5, practice 5.1, seek area 5.5, Einstein Formula 1, introduction 1.1, what is this? In this article (it is definitely tailored to beginners), you can learn how to get data from users and use them. You and need too much C language foundation. 1.2, what need to do? Please read the first "C Introduction" of C Quick Start. You also need a C compiler. If you don't have read the first article of C quick start, you can find it in the Code.box.sk C / C section. I suggest you copy and paste these code. Instead, you should try it yourself, which allows you to understand your grammar. 2, console output 2.1, escape characters to display our own name, you can write: cout << "Bill Gates";

But if we need to display:

My name is "bill"

How to do it? This seems to be a bit difficult because the dual quotes represent the beginning and end of a string in the COUT statement. For example, "That Is A String" is not possible to display double quotes on the screen. "/" Is used to solve this problem, so if you need to display:

My name is "bill"

You can write this:

Cout << "My name is /" bill / ""

Essence symbols ----------------- / n - "Return /" - "Output Double Quotes / '-" Output Single Quarantin // " Output backslash / T - "Emotive (Mobile 8) / A -" Warning ("Dudo" sound)

2.2, basic operations To display numbers without adding double quotes, for example:

COUT << "a Number:" << 2600 << endl;

! Note: A "<<" is required on the left side of each. You can also achieve simple operations in COUT, for example:

COUT << "Total Money:" << ((5 * 34) (5 * 17)) << ENDL;

Operator action -------- - "Add - -" subtraction / - "除 法 * -" Multiplication% - "

3, variable 3.1, what is a variable? Definition: Variable is a named memory address for storing data. Is it too embarrassing? In fact, variables can be metaphorical metaphors as an empty bottle. This empty bottle can be filling by users and programmers. It must first define the type and identifier before using the variable. The type of variable indicates what data can be stored this variable. A variety of different data types will be discussed in 3.2. The identifier of the variable is actually the name of the variable. Please see the following example: int Counter;

This example defines a variable used to store shaping (int) data and name "counter". Variables are used to store data. You can assign a value for a variable:

Counter = 35;

The alignment is assigned, and its effect is to store 35 into the unit name "counter" in the memory. At 4.2 There is a sample program to describe the role of the variable. 3.2, data type programmers can define their own data types, and C also provides some pre-defined types. Let's first learn about these C self-contained data types:

Type Description ------------------------ Double floating point (double): 1 / (10 * 308) to 10 * 308 ( or -) Interest (int): - 32,767 to 32,767 long integer (long): - 2,147,483,647 TO 2, 147, 483, 647 Character type (CHAR): All printable and displayed characters

Next, let's come one by one. 3.3, Integer (INT) and Long Integer (long) integers and long integers are used to store positive or negative integers. The only difference between integer and long integer is different from the range of storage data. If a decimal is stored in a integer variable, the fractional portion will be cut off. 3.4, Double floating-point (double floating point) Double floating point is used to store positive or negative realities. When we show very large or very small numbers, the computer will use a scientific count method. 3.5, character type (char) character type is used to store a character. The characters include all characters that can be displayed, such as numbers, letters and symbols: ^ # $ ~ @ 2çþ, etc. E.g:

CHAR IAMACHAR; Iamachar = 'c'; cout << iamachar <<

Show C. 3.6, constant constants are added to "const" before a variable statement. E.g:

Const Double Pi = 3.14159;

Thus, the identifier PI will represent 3.14159 throughout the operation of the entire program. It cannot be assigned because it is constant. The value trying to change a constant will result in compilation errors. 4. Console input (CIN) 4.1, how to do? The program will become more useful when the user can make an interactive operation. The console input pauses a program and allows the user to enter data as a variable assignment. E.g:

CIN >> Counter;

This statement allows the program waiting for the user to enter a data to assign a value of the variable counter. CIN and COUT are both Iostream libraries, but the console input stream at CIN. ">>" is called "acquisition operator" or "extraction operator" for obtaining data from the input stream. 4.2, Example Program The following is a sample program for demonstration variables and CIN usage:

/ * From code.box.sk mp3 evaluation program * /

#include

INT main () {int Rate; // rate variable definition COUT << "please rate Jotun by Entering a number between 1-5:"; cin >> rate; // Get an evaluation from the user COUT << "You Gave Jotun << (rate * 20) << "percent";

Return (0);

First, the user is required to enter a level between 1 to 5 for the MP3 of Jotun, and then this level will be converted to a percent system and display. 5. Exercise 5.1, ask an area to compose a formula of the radius of the user input. If the program does not work properly, please check the grammar carefully. 5.2, Einstein formula calculates energy that can be released according to user-defined quality and Einstein formula E = MCC.

转载请注明原文地址:https://www.9cbs.com/read-30345.html

New Post(0)