Write a Program and Implementation in C++

write a program

Table of Contents

C++ write a program and implementation

Write a program in c++:- I have already seen some programs written in C++. However, writing the program does not mean that the problem has been It was resolved, because it has not been run on the computer yet, and the final result has not been obtained. A program is written to run the result has to go through the following steps.



Steps of Program Writing:

Write a program in C++

The so-called program is a set of instructions that a computer system can recognize and execute. Each instruction makes the computer execute special Set operation. Programs written in high-level languages ​​are called “source programs”. The source program of C++ is With .cpp as the suffix (cpp is the abbreviation of cplus plus).

Compile the source program

Fundamentally speaking, computers can only recognize and execute binary instructions composed of 0 and 1, but cannot recognize and execute instructions. Run instructions written in high-level languages. In order to enable the computer to execute high-level language source programs, it must first be Interpreter (complier)” software (also called compiler or compilation system), the source program is translated into binary form “target “Object program”. Compilation is based on the source program file as the unit of compilation, each program unit composes a source program file, if there are multiple program units, the system compiles them into multiple target programs. The target program is generally .obj or .0 It is a suffix (short for object). The function of the compiler is to perform lexical and grammatical checks on the source program. Law check is

Check the spelling of words in the source program, for example, misspell main as mian. Grammar check is based on the source program To check the program syntax for errors, for example, output the value of variable a in the cout statement, but in the front The variable a is not defined. Check all contents in the file when compiling, and finally display all Compilation error message. Generally, the error messages given by the compilation system are divided into two types, one is error; the other is Warning, refers to some minor errors that do not affect the operation (such as A variable is defined, but it has not been used Over). If the error of the error class is checked, the target program will not be generated and must be corrected and recompiled. )

write a program
figure 1.6

Connect the target

file f.cpp After correcting all errors and compiling them, one or more object files are obtained. At this time, use the system to mention The “linker” provided by Start The program is connected with the library files of the system and other information provided by the system Finally, an executable binary file is formed, whose suffix is edit .exe, can be executed directly. Orphan program Compile.


Run the program

Have Run the final executable binary file (.exe file) Wrong? target program f.obj Files), get the running result. no connection

Analyze the running results Executable

Target program and other]) f.exe Execution of bidding procedures If the running result is not correct, check whether the program or algorithm is has a problem. Incorrect result The above process is shown in Figure 1.6. The solid line represents the operation flow correct? The dashed line indicates the input and output of the file.

For example, after editing, you get a Source program file f. cpp, and then compile the source program End File f. cpp input, after compilation, the target program file f. obj, Figure 1.6 Then enter the target program file f. obj into the memory, and the library provided by the system Files, etc. are connected to obtain the executable file f. exe, and finally f.exe is transferred into the memory and executed. Library file “correct”.

C++ Programm Writing Examples:

C++ Programming Example: Write a program that inputs a character and displays its ASCII code using cin cout stream objects:

Output:


C++ Programming Example: Write a program that inputs time in seconds and converts it into standard format (such as hh:mm:ss format) using cin cout stream objects:

Output:

C++ Programming Example: A car can travel 5.3 miles in one liter. Write a program that inputs petrol in liters and displays how much distance the car can cover using the available petrol using cin cout stream objects:

Output:

C++ Programming Example:  write a program that inputs the name, age, height and gender of a student using ‘cin C++ stream  object’:

Flowchart:

write a program

write a program



C++ Programming Example:  write a program that inputs distance in miles from user and converts miles into kilometers. One mile =1.609 kilometer using cin cout stream objects:

write a program

C++ Programming Example:  write a program in C++ to converts pound into kilograms using cin cout stream objects:

1 pound = 0.453592

write a program

C++ Programming Example:  write a program in C++ which convert Inches to centimeters using cin cout stream objects:

1 inch = 2.54 centimeters

write a program


Example write a program that computes the volume of a cylinder using const qualifier. The formula to find the volume to cylinder is: volume. The value of  is 3.1417:

write a program

Example write program that computes the area of a circle using constant define directive. The formula to find the area of a circle is: area. The value of  is 3.1417.

write a program


Related Article:

String Function: strtok, strcmp, strcpy, strlen, strstr, strcat, strcat in c++

Recommended For You

About the Author: Fawad

My name is Shahzada Fawad and I am a Programmer. Currently, I am running my own YouTube channel "Expertstech", and managing this Website. My Hobbies are * Watching Movies * Music * Photography * Travelling * gaming and so on...

Leave a Reply

%d bloggers like this: