Вы находитесь на странице: 1из 40

Worksheet 1 Programming Report

DKC2306 INTRODUCTION TO FUNDAMENTAL PROGRAMMING

MUHAMAD FIRDAUS BIN ADNAN (K12115049)


SEMESTER 2
DEPARTMENT OF COMPUTER ENGINEERING TECHNOLOGY
SUBMITTED TO: PN HALIMATON BINTI ISHAK

Worksheet 1 Programming Report

DKC2306

Report Contents
Worksheet 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

MUHAMAD FIRDAUS BIN ADNAN (K12115049)

Worksheet 1 Programming Report

DKC2306

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.

MUHAMAD FIRDAUS BIN ADNAN (K12115049)

Worksheet 1 Programming Report

DKC2306

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.

MUHAMAD FIRDAUS BIN ADNAN (K12115049)

Worksheet 1 Programming Report

DKC2306

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

4. Next step is proceed by clicking Next button.

MUHAMAD FIRDAUS BIN ADNAN (K12115049)

Worksheet 1 Programming Report

DKC2306

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

6. New Item was created by right-clicked on the Source folder in the Solution Explorer Tab.

MUHAMAD FIRDAUS BIN ADNAN (K12115049)

Worksheet 1 Programming Report

DKC2306

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

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

MUHAMAD FIRDAUS BIN ADNAN (K12115049)

Worksheet 1 Programming Report

DKC2306

Exercise 1

1. The code is type as shown in picture above.

2. Compilation process is done by Clicking BUILD > Compile.

3. Build Solution process was done by clicking on BUILD > Build Solution.
MUHAMAD FIRDAUS BIN ADNAN (K12115049)

Worksheet 1 Programming Report

DKC2306

4. Output of the Compilation process.

5. The Code is started to run by selecting Start Without Debugging under DEBUG menu.

6. The output of the source code Hello World.

MUHAMAD FIRDAUS BIN ADNAN (K12115049)

Worksheet 1 Programming Report

DKC2306

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.

MUHAMAD FIRDAUS BIN ADNAN (K12115049)

Worksheet 1 Programming Report

DKC2306

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.

MUHAMAD FIRDAUS BIN ADNAN (K12115049)

10

Worksheet 1 Programming Report

DKC2306

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.


MUHAMAD FIRDAUS BIN ADNAN (K12115049)

11

Worksheet 1 Programming Report

DKC2306

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.


MUHAMAD FIRDAUS BIN ADNAN (K12115049)

12

Worksheet 1 Programming Report

DKC2306

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.

MUHAMAD FIRDAUS BIN ADNAN (K12115049)

13

Worksheet 1 Programming Report

DKC2306

4. The output from the source code.

Question 1

1. The code was write as shown in picture above.

MUHAMAD FIRDAUS BIN ADNAN (K12115049)

14

Worksheet 1 Programming Report

DKC2306

2. The Source code.


#include <iostream>
using namespace std;
int main()
{
cout << "..::About Myself::..\n\n";
cout << "Muhamad Firdaus Bin Adnan\n";
cout << "22 years old\n";
cout << "Sultan Mohamad Jiwa Science Secondary School\n";
cout << "Cycling and Playing computer games\n";
cout << "programmer" << endl;
return 0;
}

3. The output from compile process.

4. The output from the Build solution process.

5. Screenshot of the output from the source code.


MUHAMAD FIRDAUS BIN ADNAN (K12115049)

15

Worksheet 1 Programming Report

DKC2306

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.

MUHAMAD FIRDAUS BIN ADNAN (K12115049)

16

Worksheet 1 Programming Report

DKC2306

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 <iostream>
using namespace std;
int main()
{
cout << "Every C++ program";
cout << "\nmust have one and only one";
cout << "main function";
cout << "\n the escape sequence of characters";
cout << "\nfor a newline can be placed anywhere";
cout << "\n within the messafe passed to cout" << endl;
return 0;
}

MUHAMAD FIRDAUS BIN ADNAN (K12115049)

17

Worksheet 1 Programming Report

DKC2306

3. The output from the Compile process.

4. The output from the Build Solution process.

5. The output from the source code.

MUHAMAD FIRDAUS BIN ADNAN (K12115049)

18

Worksheet 1 Programming Report

DKC2306

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 is
statements 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

MUHAMAD FIRDAUS BIN ADNAN (K12115049)

19

Worksheet 1 Programming Report

DKC2306

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.

MUHAMAD FIRDAUS BIN ADNAN (K12115049)

20

Worksheet 1 Programming Report

DKC2306

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.

MUHAMAD FIRDAUS BIN ADNAN (K12115049)

21

Worksheet 1 Programming Report

DKC2306

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.

MUHAMAD FIRDAUS BIN ADNAN (K12115049)

22

Worksheet 1 Programming Report

DKC2306

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.

MUHAMAD FIRDAUS BIN ADNAN (K12115049)

23

Worksheet 1 Programming Report

DKC2306

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.

MUHAMAD FIRDAUS BIN ADNAN (K12115049)

24

Worksheet 1 Programming Report

DKC2306

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.


MUHAMAD FIRDAUS BIN ADNAN (K12115049)

25

Worksheet 1 Programming Report

DKC2306

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.

MUHAMAD FIRDAUS BIN ADNAN (K12115049)

26

Worksheet 1 Programming Report

DKC2306

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.


MUHAMAD FIRDAUS BIN ADNAN (K12115049)

27

Worksheet 1 Programming Report

DKC2306

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.


MUHAMAD FIRDAUS BIN ADNAN (K12115049)

28

Worksheet 1 Programming Report

DKC2306

Worksheet 1(c)
Introduction
This worksheet will guide and introduce input statement and constant in C++ programming.

Objectives

Handle input statement


Define constant

MUHAMAD FIRDAUS BIN ADNAN (K12115049)

29

Worksheet 1 Programming Report

DKC2306

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.


MUHAMAD FIRDAUS BIN ADNAN (K12115049)

30

Worksheet 1 Programming Report

DKC2306

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.


MUHAMAD FIRDAUS BIN ADNAN (K12115049)

31

Worksheet 1 Programming Report

DKC2306

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.

MUHAMAD FIRDAUS BIN ADNAN (K12115049)

32

Worksheet 1 Programming Report

DKC2306

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.

MUHAMAD FIRDAUS BIN ADNAN (K12115049)

33

Worksheet 1 Programming Report

DKC2306

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.

MUHAMAD FIRDAUS BIN ADNAN (K12115049)

34

Worksheet 1 Programming Report

DKC2306

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.

MUHAMAD FIRDAUS BIN ADNAN (K12115049)

35

Worksheet 1 Programming Report

DKC2306

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

MUHAMAD FIRDAUS BIN ADNAN (K12115049)

36

Worksheet 1 Programming Report

DKC2306

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.

MUHAMAD FIRDAUS BIN ADNAN (K12115049)

37

Worksheet 1 Programming Report

DKC2306

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

MUHAMAD FIRDAUS BIN ADNAN (K12115049)

38

Worksheet 1 Programming Report

DKC2306

Question 1 (b)
Celsius
50
55
60
65
70

Fahrenheit
122
131
140
149
158

Answer:

MUHAMAD FIRDAUS BIN ADNAN (K12115049)

39

Вам также может понравиться