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

Collage of Engineering (COE) EEEB114: Programming For Engineers

LAB 4: Getting Started with CodeBlocks!


Student Name: Student ID: Section:

4.1) LEARNING OBJECTIVES


By the end of this lab session, you should be able to:
Write, save, compile, build and execute a simple program example by using CodeBlocks.

4.2) PRE LAB ASSIGNMENT


Go to this website: http://www.codeblocks.org/downloads/26 and download codeblocks-
13.12mingw-setup-TDM-GCC-481.exe. Double click the installer and complete the installation.
Once complete, launch CodeBlocks and read the CodeBlocks Manual. CodeBlocks Manual is
accessible at Help > CodeBlocks Menu as shown in Figure 3.1.

Figure 3.1 CodeBlocks Manual

Page 1 of 10
Prepared By Sarveswaren May 2015
Collage of Engineering (COE) EEEB114: Programming For Engineers

4.3) BACKGROUND
CodeBlocks is an open source platform with full-featured integrated development environment
(IDE). The version used in this course is 13.12 rev 9501 and is made available at
www.codeblocks.org.

4.4) IN LAB ACTIVITIES


Activity A: Creating a New Project
1. From Windows menu, select:

All Programs > CodeBlocks > CodeBlocks


2. From the menu bar, select File > New > Project. The pop up window shown in Figure 3.2 will
appear.

Figure 3.2 Pop up window for creating new project

Page 2 of 10
Prepared By Sarveswaren May 2015
Collage of Engineering (COE) EEEB114: Programming For Engineers

3. Click on Console application icon and click Go. Click Next on Console Application wizard as
shown in Figure 3.3.

Figure 3.3 Console application wizard

4. Select C language and click Next as shown in Figure 3.4

Figure 3.4 Programming language selection


Page 3 of 10
Prepared By Sarveswaren May 2015
Collage of Engineering (COE) EEEB114: Programming For Engineers

5. Type Worksheet 4 as project title and click Next as shown in Figure 3.5

Figure 3.5 Project title

6. Click Finish to accept the default configurations as shown in Figure 3.5.

Figure 3.5 Compiler selection


Page 4 of 10
Prepared By Sarveswaren May 2015
Collage of Engineering (COE) EEEB114: Programming For Engineers

Figure 3.6 A new project titled Worksheet 4 is successfully created

Page 5 of 10
Prepared By Sarveswaren May 2015
Collage of Engineering (COE) EEEB114: Programming For Engineers

Activity B: Writing a C Program


1. Choose Projects tab under the Management pane. Expand the Worksheet4 project
node. Expand Source node and double click main.c.

Figure 3.7 Hello world code

2. Click Build and run under Build menu.

Page 6 of 10
Prepared By Sarveswaren May 2015
Collage of Engineering (COE) EEEB114: Programming For Engineers

Figure 3.8 Executing Hello world code


3. Observe the output as shown in Figure 3.9. Press any key to continue.

Figure 3.9 Hello world!

Page 7 of 10
Prepared By Sarveswaren May 2015
Collage of Engineering (COE) EEEB114: Programming For Engineers

4. Copy and paste the following code to replace Hello world! code. Click Build and Run.
What is the output? Print screen the output and insert right after the code.
#include <stdio.h>

int main()
{
printf("I like programming in C.\n");
return 0;
}

Figure 3.9 New code


5. Recall Section 4 of Chapter 1 as shown in Figure 3.10.

Figure 3.10 I like programming in C. code

Page 8 of 10
Prepared By Sarveswaren May 2015
Collage of Engineering (COE) EEEB114: Programming For Engineers

6. Now, copy and paste the following code (from Worksheet 2) and execute the program.
/*
* Calculates and displays the area and circumference of a circle
*/

#include <stdio.h>
#define PI 3.14159

int
main()
{
double radius, /* input radius of circle*/
area, /* output radius of circle*/
circum; /* output radius of circle*/

/*Ask user to enter the radius of circle*/


printf("\nEnter radius of circle: ");
/*Storing the user input into variable radius*/
scanf("%lf",&radius);

/*Calculate Area and Circumference*/


area = PI * radius * radius;
circum = 2 * PI * radius;

/*Display Area and Circumference*/


printf("\nArea of circle is: %f",area);
printf("\nCircumference of circle is: %f",circum);

return(0);
}

7. Enter 5 for radius of the circle. Print screen and insert the output below.

Page 9 of 10
Prepared By Sarveswaren May 2015
Collage of Engineering (COE) EEEB114: Programming For Engineers

4.5) STATE YOUR LEARNING CURVE


Note: conclude what youve learned from this lab activity.

Page 10 of 10
Prepared By Sarveswaren May 2015

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