17
HOW TO MAKE C++ programming 1.)First open c++

Job Sheet 5 Muhamad Hakimi Azali Bin Azlan

  • Upload
    hakimi

  • View
    37

  • Download
    1

Embed Size (px)

DESCRIPTION

js 05 muhamad hakimi azali bin azlan

Citation preview

Page 1: Job Sheet 5 Muhamad Hakimi Azali Bin Azlan

HOW TO MAKE C++ programming

1.)First open c++

Page 2: Job Sheet 5 Muhamad Hakimi Azali Bin Azlan

2.)second select new source file

Page 3: Job Sheet 5 Muhamad Hakimi Azali Bin Azlan

3)then write this program in the new source file

/*this is a program that computes the sum of two integer number*/

#include <iostream.h>

#include <stdlib.h>

int main()

{

int x,y,sum;

cout<<"\nEnter first number :";

cin>>x;

cout<<"\nntr second number:";

cin>>y;

sum=x+y;

cout<<"\nsum="<<sum;

system("PAUSE");

return 0;

}

Page 4: Job Sheet 5 Muhamad Hakimi Azali Bin Azlan

this is the example

Page 5: Job Sheet 5 Muhamad Hakimi Azali Bin Azlan

4.)and the after we write the program,check if everything corrected,open the compilation process.

Page 6: Job Sheet 5 Muhamad Hakimi Azali Bin Azlan

5 then we press run progress.

Page 7: Job Sheet 5 Muhamad Hakimi Azali Bin Azlan

6.)then after press the run button,we insert the number

Page 8: Job Sheet 5 Muhamad Hakimi Azali Bin Azlan

7)then save the file

Page 9: Job Sheet 5 Muhamad Hakimi Azali Bin Azlan

1)How to Compilation Process

The C++ compilation process

Compiling a source code file in C++ is a four-step process. For example, if you have a C++ source code file named prog1.cpp and you execute the compile command

Page 10: Job Sheet 5 Muhamad Hakimi Azali Bin Azlan

g++ -Wall -ansi -o prog1 prog1.cpp

the compilation process looks like this:

1. The C++ preprocessor copies the contents of the included header files into the source code file, generates macro code, and replaces symbolic constants defined using #define with their values.

2. The expanded source code file produced by the C++ preprocessor is compiled into the assembly language for the platform.

3. The assembler code generated by the compiler is assembled into the object code for the platform.

4. The object code file generated by the assembler is linked together with the object code files for any library functions used to produce an executable file.

By using appropriate compiler options, we can stop this process at any stage.

1. To stop the process after the preprocessor step, you can use the -E option:2. g++ -E prog1.cpp

The expanded source code file will be printed on standard output (the screen by default); you can redirect the output to a file if you wish. Note that the expanded source code file is often incredibly large - a 20 line source code file can easily produce an expanded file of 20,000 lines or more, depending on which header files were included.

3. To stop the process after the compile step, you can use the -S option:4. g++ -Wall -ansi -S prog1.cpp

By default, the assembler code for a source file named filename.cpp will be placed in a file named filename.s.

5. To stop the process after the assembly step, you can use the -c option:6. g++ -Wall -ansi -c prog1.cpp

By default, the assembler code for a source file named filename.cpp will be placed in a file named filename.o.

Page 11: Job Sheet 5 Muhamad Hakimi Azali Bin Azlan

2)How to xecute the program

1. Write and save the program

Open a simple text editor (e.g gedit), IDE (Eclipse) or command line code editor (Nano or Vim). I’ll be using gedit as it is very simple to use and it’s recommended for beginner programmers. Right Click on Desktop or any directory (Browse File using Nautilus) and select create new File – hello.c (.c extension is used to indicate that it’s a c program). Then write a simple program like this (and save the program press Ctrl+S)

#include<stdio.h>

void main()

{

printf("Hello! This is my first C program with Ubuntu 11.10\n");

/* Do something more if you want */

Page 12: Job Sheet 5 Muhamad Hakimi Azali Bin Azlan

}

2. Compile the program

GCC (GNU Compiler Collection) is installed by default, in Ubuntu. To compile the program, open the terminal and move on to the target directory type the command – (where gcc implies compiler name, then it asks for the file name of the source program while -o option specifies the file name of the output program)

gcc hello.c -o hello1

If there is no syntax/semantic error in you program then the compiler will successfully generate an executable file, otherwise fix the problem in your code.

3. Execute the program

To execute the program, you need to run –

./hello1

Page 13: Job Sheet 5 Muhamad Hakimi Azali Bin Azlan

What is c++ programming

C++ (pronounced as cee plus plus, / ̍ s i ː  p l ʌ s  p l ʌ s / ) is a general-purpose programming language. It

has imperative, object-oriented and generic programming features, while also providing the facilities

for low-level memory manipulation.

It is designed with a bias toward system programming (e.g., for use in embedded

systems or operating system kernels), with performance, efficiency and flexibility of use as its design

requirements. C++ has also been found useful in many other contexts, including desktop

applications, servers (e.g. e-commerce, web search or SQL servers), performance-critical

applications (e.g. telephone switches or space probes), and entertainment software.[3] C++ is

a compiled language, with implementations of it available on many platforms and provided by

various organizations, including the FSF, LLVM, Microsoft and Intel.

C++ is standardized by the International Organization for Standardization (ISO), with the latest (and

current) standard version ratified and published by ISO in December 2014 as ISO/IEC

14882:2014 (informally known asC++14).[4] The C++ programming language was initially

standardized in 1998 as ISO/IEC 14882:1998, which was then amended by the C++03, ISO/IEC

14882:2003, standard. The current C++14 standard supersedes these and C++11, with new

features and an enlarged standard library. Before the initial standardization in 1998, C++ was

developed by Bjarne Stroustrup at Bell Labs, starting in 1979, who wanted an efficient flexible

language (like the C language), which also provided high-level features for program organization.

Many other programming languages have been influenced by C++, including C#, Java, and newer

versions of C (after 1998).

Page 14: Job Sheet 5 Muhamad Hakimi Azali Bin Azlan

Conclusion

I have learn and I be able to practice the usage of the c++ software,begin c++ programming,use all structures in c++ programming,state all functions in c++ programming and demonstrate output running of the c++ programming.