c++ programming report

Upload: pulutdakap

Post on 20-Feb-2018

222 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/24/2019 C++ Programming report

    1/40

    MUHAMAD FIRDAUS BIN ADNAN (K12115049)SEMESTER 2

    DEPARTMENT OF COMPUTER ENGINEERING TECHNOLOGY

    SUBMITTED TO: PN HALIMATON BINTI ISHAK

    Worksheet 1 Programming ReportDKC2306 INTRODUCTION TO FUNDAMENTAL PROGRAMMING

  • 7/24/2019 C++ Programming report

    2/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 1

    Report ContentsWorksheet 1(a) ............................................................................................................................................. 2

    Introduction .............................................................................................................................................. 2

    Objectives ................................................................................................................................................. 2

    Create a new project and file .................................................................................................................... 3

    Exercise 1 .................................................................................................................................................. 7

    Exercise 2 .................................................................................................................................................. 9

    Exercise 3 ................................................................................................................................................ 11

    Exercise 4 ................................................................................................................................................ 12

    Exercise 5 ................................................................................................................................................ 13

    Question 1 ............................................................................................................................................... 14

    Question 2 (a) and (b) ............................................................................................................................. 16

    Question 3 ............................................................................................................................................... 17

    Worksheet 1(b) ........................................................................................................................................... 19

    Introduction ............................................................................................................................................ 19

    Objectives ............................................................................................................................................... 19

    Exercise 1 ................................................................................................................................................ 20

    Exercise 2 ................................................................................................................................................ 21

    Exercise 3 ................................................................................................................................................ 22

    Exercise 4 ................................................................................................................................................ 23

    Exercise 5 ................................................................................................................................................ 24

    Exercise 6 ................................................................................................................................................ 25

    Exercise 7 ................................................................................................................................................ 26

    Exercise 8 ................................................................................................................................................ 27

    Question 1 ............................................................................................................................................... 28

  • 7/24/2019 C++ Programming report

    3/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 2

    Worksheet 1(c) ............................................................................................................................................ 29

    Introduction ............................................................................................................................................ 29

    Objectives ............................................................................................................................................... 29

    Exercise 1 ................................................................................................................................................ 30

    Exercise 2 ................................................................................................................................................ 31

    Exercise 3 ................................................................................................................................................ 32

    Exercise 4 ................................................................................................................................................ 33

    Exercise 5 ................................................................................................................................................ 34

    Exercise 6 ................................................................................................................................................ 35

    Exercise 7 ................................................................................................................................................ 36

    Exercise 8 ................................................................................................................................................ 37

    Question 1a ............................................................................................................................................. 38

    Question 1 (b) ......................................................................................................................................... 39

    Worksheet 1(a)

    Introduction

    This worksheet will guide and introduce the C / C++ programming environment. This simple program will

    show how to create a program using the C / C++ language.

    Objectives

    Create a new project and file.

    Type the source codes.

    Compile and execute the project.

  • 7/24/2019 C++ Programming report

    4/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 3

    Create a new project and file

    1.

    Microsoft Visual Studio opened and shows the main interface.

    2.

    New project was created by clicking on FILE > New > Project.

  • 7/24/2019 C++ Programming report

    5/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 4

    3. Visual C++ is chose and Win32 Console Application. The file was renamed as Lab1.

    4.

    Next step is proceed by clicking Nextbutton.

  • 7/24/2019 C++ Programming report

    6/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 5

    5.

    The option is set as show in the picture above. Clicking Finishwill proceed to main windows.

    6. New Itemwas created by right-clicked on the Source folder in the Solution ExplorerTab.

  • 7/24/2019 C++ Programming report

    7/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 6

    7. C++ File (.cpp)is selected and renamed as exercise1. Click Add.

    8.

    Main Workspace is showed. The code ready to be typed in.

  • 7/24/2019 C++ Programming report

    8/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 7

    Exercise 1

    1.

    The code is type as shown in picture above.

    2.

    Compilation process is done by ClickingBUILD > Compile.

    3.

    Build Solution process was done by clicking on BUILD > Build Solution.

  • 7/24/2019 C++ Programming report

    9/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 8

    4.

    Output of the Compilation process.

    5.

    The Code is started to run by selecting Start Without Debugging under DEBUGmenu.

    6.

    The output of the source code Hello World.

  • 7/24/2019 C++ Programming report

    10/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 9

    Exercise 2

    1.

    New item was created under Source File by right-clicking on it and select Add > New item.

    2.

    New file was renamed to exercise2.

  • 7/24/2019 C++ Programming report

    11/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 10

    3.

    The code was typed as shown in picture above.

    4.

    The output after Compilation and Build Solution process.

    5.

    The output of the source code.

  • 7/24/2019 C++ Programming report

    12/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 11

    Exercise 3

    1.

    The code was typed as shown in picture above.

    2.

    The output after compile process.

    3.

    The output after Build Solution process.

    4.

    The output of the source code.

  • 7/24/2019 C++ Programming report

    13/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 12

    Exercise 4

    1.

    The code was written as shown in picture above.

    2.

    The output from the Compile process.

    3.

    The output from the Build Solution process.

    4.

    The output from the source code.

  • 7/24/2019 C++ Programming report

    14/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 13

    Exercise 5

    1.

    The code was written as shown in picture above.

    2.

    The output from the Compile process.

    3.

    The output from the Build Solution process.

  • 7/24/2019 C++ Programming report

    15/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 14

    4.

    The output from the source code.

    Question 1

    1.

    The code was write as shown in picture above.

  • 7/24/2019 C++ Programming report

    16/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 15

    2.

    The Source code.

    3.

    The output from compile process.

    4.

    The output from the Build solution process.

    5.

    Screenshot of the output from the source code.

    #includeusingnamespacestd;

    intmain(){

    cout

  • 7/24/2019 C++ Programming report

    17/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 16

    Question 2 (a) and (b)

    1.

    The code is written based on the question given.

    2.

    The output from compile process.

    3.

    The output from build solution process.

    4.

    The output from the source code.

  • 7/24/2019 C++ Programming report

    18/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 17

    a.

    The program works.

    b. Its not a good program because it is difficult to read the source code besides the arrangement is

    not properly arrange which cause the user difficult to find any error if the error occur.

    Question 3

    1.

    The source code was written back in proper line and arrangement.

    2.

    The Source code.

    #include

    usingnamespacestd;

    intmain(){

    cout

  • 7/24/2019 C++ Programming report

    19/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 18

    3.

    The output from the Compile process.

    4.

    The output from the Build Solution process.

    5.

    The output from the source code.

  • 7/24/2019 C++ Programming report

    20/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 19

    Worksheet 1(b)

    Introduction

    This worksheet will guide and introduce several basic types of variable which the C++ can recognize. All

    variables in program must be declared in a program before it can be used. Output statement isstatements used to display information on screen or other output devices.

    Objectives

    Declare and define variables

    Assign values to variables and manipulate those values

    Handle output statement

  • 7/24/2019 C++ Programming report

    21/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 20

    Exercise 1

    1.

    The code was written as shown in picture above.

    2.

    The output from the Compile process.

    3.

    The output from the Build Solution process

    4.

    The output from the source code.

  • 7/24/2019 C++ Programming report

    22/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 21

    Exercise 2

    1.

    The code was write as shown in picture above.

    2.

    The output from the compile process.

    3.

    The output from the build solution process.

    4.

    The output from the source code.

  • 7/24/2019 C++ Programming report

    23/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 22

    Exercise 3

    1.

    The code was written as shown in picture above.

    2.

    The output from the compile process.

    3.

    The output from the build solution process.

    4.

    The output from the source code.

  • 7/24/2019 C++ Programming report

    24/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 23

    Exercise 4

    1.

    The code was written as shown in picture above.

    2.

    The output from the compile process.

    3.

    The output from the build solution process.

    4.

    The output from the source code.

  • 7/24/2019 C++ Programming report

    25/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 24

    Exercise 5

    1.

    The code was written as shown in picture above.

    2.

    The output from the compile process.

    3.

    The output from the build solution process.

    4.

    The output from the source code.

  • 7/24/2019 C++ Programming report

    26/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 25

    Exercise 6

    1.

    The code is written as shown in picture above.

    2.

    The output from the compile process.

    3.

    The output from the build solution process.

    4.

    The output from the source code.

  • 7/24/2019 C++ Programming report

    27/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 26

    Exercise 7

    1.

    The code was written as shown in picture above.

    2.

    The output from the compile process.

    3.

    The output from the build solution process.

    4.

    The output from the source code.

  • 7/24/2019 C++ Programming report

    28/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 27

    Exercise 8

    1.

    The code was written as shown in picture above.

    2.

    The output of the compile process.

    3.

    The output from the build solution process.

    4.

    The output from the source code.

  • 7/24/2019 C++ Programming report

    29/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 28

    Question 1

    1.

    The code was written as shown in picture above.

    2.

    The output from the compile process.

    3.

    The output from the build solution process.

    4.

    The output from the source code.

  • 7/24/2019 C++ Programming report

    30/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 29

    Worksheet 1(c)

    Introduction

    This worksheet will guide and introduce input statement and constant in C++ programming.

    Objectives

    Handle input statement

    Define constant

  • 7/24/2019 C++ Programming report

    31/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 30

    Exercise 1

    1.

    The code was written as shown in picture above.

    2.

    The output from the compile process.

    3.

    The output from the build solution process.

    4.

    The output from the source code.

  • 7/24/2019 C++ Programming report

    32/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 31

    Exercise 2

    1.

    The code was written as shown in figure above.

    2.

    The output from the compile process.

    3.

    The output from the build solution process.

    4.

    The output from the source code.

  • 7/24/2019 C++ Programming report

    33/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 32

    Exercise 3

    1.

    The code was written as shown in picture above.

    2.

    The output from the compile process.

    3.

    The output from the build solution.

    4.

    The output from the source code.

  • 7/24/2019 C++ Programming report

    34/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 33

    Exercise 4

    1.

    This code was written as shown in picture above.

    2.

    The output from the compile process.

    3.

    The output from the build solution process.

    4.

    The output from the source code.

  • 7/24/2019 C++ Programming report

    35/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 34

    Exercise 5

    1.

    This code was written as shown on picture above.

    2.

    The output from the compile process.

    3.

    The output from the build solution process.

    4.

    The output from the source code.

  • 7/24/2019 C++ Programming report

    36/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 35

    Exercise 6

    1.

    This code was written as shown in picture above.

    2.

    The output from the compile process.

    3.

    The output of the build solution process.

    4.

    The output from the source code.

  • 7/24/2019 C++ Programming report

    37/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 36

    Exercise 7

    1.

    This code was written which as shown in picture above.

    2.

    The output from the compile process.

    3.

    The output for the compiler process.

    4.

    The output from the source code

  • 7/24/2019 C++ Programming report

    38/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 37

    Exercise 8

    1.

    This code was written as shown in picture above.

    2.

    The output from the compile process.

    3.

    The output from the build solution process.

    4.

    The output from the source code.

  • 7/24/2019 C++ Programming report

    39/40

    Worksheet 1 Programming Report DKC2306

    MUHAMAD FIRDAUS BIN ADNAN (K12115049) 38

    Question 1a

    1.

    The code was written as shown in the picture above.

    2.

    The output from the compile process.

    3.

    The output from the build solution process.

    4.

    The output from the source code

  • 7/24/2019 C++ Programming report

    40/40

    Worksheet 1 Programming Report DKC2306

    Question 1 (b)

    Celsius Fahrenheit

    50 122

    55 131

    60 140

    65 149

    70 158

    Answer: