0% found this document useful (0 votes)
9 views15 pages

SPL LAB 1

The lab manual focuses on structured programming using C, outlining objectives and course outcomes for students, including understanding programming logic, writing algorithms, and using various data structures. It provides a step-by-step guide for program development, including writing, compiling, and executing C programs, as well as details on using CodeBlocks IDE and header files. Additionally, it includes instructions for preparing lab reports and practice programs to enhance programming skills.

Uploaded by

Rakib Mia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
9 views15 pages

SPL LAB 1

The lab manual focuses on structured programming using C, outlining objectives and course outcomes for students, including understanding programming logic, writing algorithms, and using various data structures. It provides a step-by-step guide for program development, including writing, compiling, and executing C programs, as well as details on using CodeBlocks IDE and header files. Additionally, it includes instructions for preparing lab reports and practice programs to enhance programming skills.

Uploaded by

Rakib Mia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 15

Lab Manual

Strutured Programmming Language

Page 1
OBJECTIVES

1. CLO1- To understand the basic building blocks of structured programming


2. CLO2- To analyze structured program.
3. CLO3- To develop a structured program for solving computational problems.
4. CLO4- To design a structured program for complex computational applications.

COURSE OUTCOME
After completing this lab course, students will be able to:

1. Understand the logic for a given problem.


2. Write the algorithm of a given problem.
3. Draw a flow chart of a given problem.
4. Recognize and understand the syntax and construction of C programming code.
5. Gain experience in procedural language programming.
6. Know the steps involved in compiling, linking and debugging C code.
7. Understand using header files.
8. Learn the methods of iteration or looping and branching.
9. Use different data structures like arrays, pointers, structures and files.
10. Understand how to access and use library functions.
11. Understand function declaration and definition.
12. Understand proper use of user-defined functions.
13. Write programs to print output on the screen and in the files.
14. Apply all the concepts that have been covered in the theory course, and
15. Know the alternative ways of providing the solution to a given problem.

INTRODUCTION ABOUT LAB


Steps involved in program development:-

To develop the program in a high-level language and translate it into machine level
language following steps have to be practised.
1. Writing and editing the program.
2. Linking the program with the required library modules.
3. Compiling the program.
4. Executing the program.

Page 2
ALGORITHM:-

It is a method of representing the step by step process for solving a problem. Each step
is called an instruction.

Example of algorithm to find sum of two numbers:

Step1: BEGIN
Step2: READ a, b
Step3: ADD a and b and store in variable c
Step4: DISPLAY c
Step5: STOP

Hardware Requirement: Desktop Computer / laptop computer.


Software Requirement: Linux and Windows Operating system with “Codeblocks”
IDE.

CodeBlocks:
CodeBlocks is an IDE (Integrated Development Environment) used to create, edit, compile,
debug and execute C/C++ programs in single place. It is very powerful IDE for developing
C projects. It can be used in both Linux and Windows Operating System.

How to create C program file in CodeBlocks IDE:


1.Open CodeBlocks IDE and create a new file. Go to File -> New -> Empty file.

l e4

Page 3
2.Save the file with .c extention.

3.Write your first code here and then click on “Build and Run” icon.

Page 4
4.Output:

Page 5
STRUCTURE OF a C PROGRAM :
C program is a collection of several instructions where each instruction is written as a
separate statement. The C program starts with a primary function followed by the
opening braces, which indicates the start of the function. Then follows the variable and
constant declarations followed by the statements that include input and output
statements.

C program may contain one or more sections as shown below:

DOCUMENTATION SECTION
LINK SECTION
DEFINITION SECTION
GLOBAL DECLARATION SECTION
Main() Function section
{
Declaration part
Executable part
}
SUBPROGRAM SECTION
User defined functions

Page 6
Example:

HEADER FILES
Header files are helping file of your C program which holds the definitions of various
functions and their associated variables that needs to be imported into your C program with
the help of pre-processor #include statement. All the header file have a '.h' an extension that
contains C function declaration and macro definitions. In other words, the header files can be
requested using the preprocessor directive #include. The default header file that comes with
the C compiler is the stdio.h.

Including a header file means that using the content of header file in your source program.

“#include<stdio.h>” is the basic header that must be added to a C program. Other headers
that can be needed are:

1. math.h: includes mathematical function like:

abs(),sqrt(),pow(),sin(),cos(),tan(),log(),ceil(),floor(),round() etc.

2. stdlib.h: includes function like: rand(),atof(),atoll(),atoi() etc.


3. string.h: strcpy(), strcat(),strlen(),strcmp() etc.
4. ctype.h: isupper(), islower(),toupper(), tolower()

Can see more details of these functions from this website:

https://en.cppreference.com/w/c/header

Page 7
KEYWORDS
C has 32 keywords (reserved words with special meaning):

Page 8
OPERATORS

C supports a rich set of operators, which are symbols used within an expression to
specify the manipulations to be performed while evaluating that expression. C has
the following operators:
arithmetic: +, -, *, /, %
assignment: =
augmented assignment: +=, - =, *=, /=, %=, &=, |=, ^=, <<=, >>=
boolean logic: !, &&, ||
equality testing: = =, !=
calling functions: ( )
increment and decrement: ++ and - -

Page 9
INSTRUCTIONS TO STUDENTS FOR PREPARING
PROGRAMMING IN C LAB REPORT

This Lab Manual is prepared to help the students with their practical understanding and
development of programming skills and may be used as a base reference during the
lab/practical classes.

Students have to submit the Lab Exercise report of the previous lab into the
corresponding next lab. It can be collected after the instructor/course teacher has been
checked and signed. At the end of the semester, students should compile all the Lab
Exercise reports into a single report and submit them during the end semester sessional
examination.

“Sample of Lab report” is shown for LAB Exercise #1 in this manual. For the rest of
the labs, the reporting style as provided is to be followed. The lab report to be submitted
during the end semester Sessional Examination should include at least the following
topics:-
1. Top Cover page – pg. 9 (to be used while compiling all the Lab Exercise reports
into single report)
2. Index – pg. 10 (to be used while compiling all the Lab Exercise reports into single
report)
3. Cover page – pg. 11 (to be attached with every Lab Exercise)
4. Title of the program
5. Algorithm (optional)
6. Flowchart (optional)
7. Coding
8. Output (compilation, debugging & testing)

Students are to show the coding and output to the instructor/course teacher for the
additional lab exercises given in each lab module.
Note: The lab exercises may not be completed in a single specific lab. Students are
encouraged to complete the programming questions given in the exercise prior to coming
to the lab hour and do the lab for the given programs.

Page
10
Institute of Information Technology
Jahangirnagar University

SUBMITTED BY
Name:
Class Roll No.

1st Year 1st Semester in ICT (Hons.) 2021-2022


Submission Date:
Submitted to:
Md. Biplob Hosen, Lecturer, IIT-JU

Page 9
INDEX

Exercises/Assignments Page No.

1. Exercise – 1
(i) Program 1… ......................................................................... 1
(ii) Program 2 ............................................................................. 2
(iii) Program 3, etc.
2. Exercise – 2 ……………………………………………………. ..
3. Exercise – 3 ………………………
4. etc.
5. etc.

Page 10
Institute of Information Technology
Jahangirnagar University

LAB Exercise #1

Programming in C Lab Exercise Report Submitted By:

Name:

Class Roll No:

Lab Date:
Submission Date:

Page 11
LAB EXERCISE #1

Objective(s):
 To be familiar with syntax and structure of C.
 To learn problem-solving techniques using C

Program: Write a Program to calculate and display the volume of a CUBE having its
height (h=10cm), width (w=12cm) and depth (8cm).

Algorithm:
1. Start
2. Define variables: h(int), w(int), d(int), vol(int)
3. Assign value to variables: h = 10, w=12, d=8
4. Calculate the volume as: vol = h*w*d
5. Display the volume (vol)
6. Stop

Flowchart:

Page 12
Code: (Use comments wherever applicable)

//Following code is written and compiled in CodeBlocks

#include<stdio.h>
void main()
{
//start the program
int h,w,d,vol; //variables declaration
h=10, w=12, d=8; //assign value to variables
vol=h*w*d; //calculation using mathematical formula
printf("The Volume of the cube is: %d",vol); //display the volume

//end the main program


}
Output :
The Volume of the cube is: 960
Tasks to-do: Use scanf () function to tae the inputs from user.

Practice Programs

(Students are to code the following programs in the lab and show the output to
instructor/course teacher)
Instructions

 Write comment to make your programs readable.


 Use descriptive variables in your programs(Name of the variables should show
their purposes)

Programs List
1. Write a C program to add two numbers and display its sum.
2. Write a C program the average of three numbers.
3. Write a C program to calculate area of a rectangle.
4. Write a C program to calculate area and circumference of a circle.
5. Write a C program to perform addition, subtraction, division and
multiplication of two numbers.
6. Write C program to evaluate each of the following equations.
(i) V = u + at. (ii) S = ut+1/2a

Page 13

You might also like