Manual Tasks Assignment
Manual Tasks Assignment
Computer Programming
Computer programming involves developing lists of instructions - the source code representation of software.
Source code is written in one or more programming languages. Following are types of programming languages.
1. Machine Language
The fundamental language of the computer’s processor, also called Low Level Language. All programs
are converted into machine language before they can be executed. It consists of combination of 0’s and
1’s.
2. Assembly Language
A low level language that is similar to machine language. It uses symbolic operation code called
mnemonics to represent the machine operation code.
C-language
C is a high-level and general purpose programming language that is ideal for developing firmware or portable
applications. C was developed at Bell Labs by Dennis Ritchie for the Unix Operating System (OS) in the early
1970s.
C belongs to the structured, procedural paradigms of languages. It is proven, flexible and powerful and may be
used for a variety of different applications.
Ranked among the most widely used languages, C has a compiler for most computer systems and influenced
many popular languages – notably C++.
Content
Lab No. Lab Objective
1 Introduction to C
2 Console Output
3 Data Types & Variables
4 Console Input
5 Operators in C & Math functions
6 Loops
7 Selection Statements
8 Functions
9 Arrays
10 Structures
11 Pointers
12 Graphics
13 Charts – Graphics
14 Filing
15 Hardware Programming
Lab Details
Lab Marks
Lab Objective Signature
No. Obtained
Introduction to C
Objective: Getting familiar with the IDE and working with Turbo C
1
& Microsoft Visual Studio.Installing and copying the compiler,
changing directory settings.Making first program in C.
Student Feedback:
Console Output
2 Objective:Understanding and Using format specifier and escape
sequences with printf.
Student Feedback:
Console Input
4 Objective:Taking Input from the user at console screen using scanf
and getche commands.
Student Feedback:
Loops
Objective:Studying loops. For loops, nested for loops, while loops,
6
nested while loops, do while loops, nested do while loops.Studying
loops with cross combination.
Student Feedback:
Selection Statements
7 Objective:Decision making and conditioning using If statements, If-
else statements, switch-case.
Student Feedback:
Functions
8 Objective:User defined functions, passing values to function, and
returning values from functions.
Student Feedback:
Arrays
9 Objective:Arrays, array index, single and multi-dimensional arrays.
Arrays and loops. Sorting data in arrays.
Student Feedback:
Structures
10 Objective:Studying Structures, different ways to declare define and
initialize structures.
Student Feedback:
11 Pointers
Objective:Learnhow Pointers access data using memory address.
Student Feedback:
Graphics
12 Objective:Graphics, basic applications of graphics by making
buttons and animations.
Student Feedback:
13 Charts -Graphics
Objective:Draw different charts using C graphics.
Student Feedback:
Filing
14 Objective:Learn to create, open, write and close text files for data
storage With C language.
Student Feedback:
Hardware Programming
15 Objective:Understanding registers and accesses the hardware using
C language. Learn the basics of Inline Assembly.
Student Feedback:
Note: Students are advised to write their comments about whether the objective of the lab was achieved or not in
Student Feedbacksection.
Experiment 1 .
Objective
Getting familiar with the IDE and working with Turbo C &Microsoft Visual Studio. Installing and copying the compiler,
changing directory settings. Making first program in C. Saving / copying files to USB or other storage devices.
Theory
IDE
An integrated development environment (IDE) is a software suite that consolidates the basic tools developers need
to write and test software. Typically, an IDE contains a code editor, a compiler or interpreter and a debugger that the
developer accesses through a single graphical user interface (GUI). An IDE may be a standalone application, or it
may be included as part of one or more existing and compatible applications.
There are different IDE’s to write C program. Following are the two most common;
1. Turbo C
2. Microsoft Visual Studio
1. Turbo C
Turbo C is a discontinued Integrated Development Environment and compiler for the C programming language from
Borland. First introduced in 1987, it was noted for its integrated development environment, small size, fast compile
speed, comprehensive manuals and low price.In May 1990, Borland replaced Turbo C with Turbo C++.
The use of this IDE on latest OS has become very difficult as a lot of libraries are not supported any more. The use of
this IDE is depreciated.
A new window will open. From there right click on the folder named as TC3 and select copy. Now Paste in it in your C
or D partition or your USB drive. As a good approach C drive is normally not recommended for C compiler as C drive is a
windows system partition.
Assuming that the folder has been copied in the root of D drive, open D: partition- TC3 folder - BIN –
Double click and open any one of the two TC.exe icons (as shown on right).
The window that opens is the known as the IDE of Turbo C (as shown below)
6
Figure 1.2: Turbo C IDE
This IDE window further contains two more windows and a standard tool bar. The blue window is known as the text editor
which is used to write the programs. And the Light bluish green window at the bottom is the message box which will
display the error or other messages.
Before using the IDE there are few parameters and checks which need to be reviewed every time the IDE of windows is
used. Make sure that the folder of TC3 (also known as compiler) has been copied in the root drive i.e. in the first
window of any partition and not in sub folders. e.g.
Setting Directory Paths (to be checked each time the Turbo IDE is opened)
Once you have opened and saved a new file some directories need to be changed according to the location of your
compiler in your computer otherwise the compiler make not work properly.
On the standard toolbar click on options then directories. Set the first letter of the first two paths (i.e. Include Directories
and Library Directories) according to the location of the compiler or say the letter of the directory where you copied your
compiler. The other two paths (i.e. Output Directories and Source Directories) will remain blank. e.g.
8
2. Microsoft Visual Studio
Microsoft Visual Studio is an integrated development environment (IDE) from Microsoft. It is used to develop computer
programs for Microsoft Windows, as well as web sites, web applications and web services. Visual Studio uses Microsoft
software development platforms.
Visual Studio includes a code editor supporting IntelliSense as well as code refactoring. The integrated debugger works
both as a source-level debugger and a machine-level debugger. Visual Studio supports different programming
languages and allows the code editor and debugger to support nearly any programming language. Built-in languages
include C, C++, VB.NET, C# and F#.
Open Microsoft Visual Studio by double clicking on the Icon. The icon similar to the following (depending upon the version)
should be available on your desktop.
We first have to create a project. To create a new project, click on “New Project” option present on the left side. A
Window similar to the one shown below will appear. Expand the template option present on left side of the window.
Select “Visual C++” and under this, select “General” option. Select first option “Empty Project” from the middle
section. Provide name for the project as “Lab1” and press OK.
9
Figure 1.6: Create new project
After you click OK, following screen will be displayed which has a Solution Explorer on the right hand side. This panel will be used to
access all the files of the project.
Now right click on your project “Lab1, and go to Add and then select New item, refer to the screenshot below.
10
Figure 1.8: Add new item
A window similar to one given below will appear. Select Visual C++ and code from the left panel. Select C++ file from
the middle panel. Give a name to your source file. This will by default create a file with .cpp extension which
represents(C++) but we have to create a C file. Change the extension to .c and click Add.
Your file will appear in solution explorer under folder Source Files.
11
Figure 1.10: File created under Source Files
Now you can simply add a C program and execute the file.
First C Program
#include<stdio.h>
#include<conio.h>
The first line of this program is #include<stdio.h> . Here #include tells the compiler to include something and stdio means
Standard Input/Output where as .h means that it is a header file or in short we are including standard input/output header
file. In the same way the next line is similar to the first one but it has conio.h in it where conio means the black colour
console screen where we see our output and .h tells us that this is a header file. In other words we tell the compiler that
we are including two files and the code we will write will be of c language as the compiler also supports C++ code.
int main()
This is third line. The first word in this is void which means any thing that has no value or is useless. The next word is
main which is the brain function and is the only function readable in most programming languages. All the other functions
are called within the main function. The third word within brackets is also void. The first void means that the main function
won’t return any value while the second void means that the main function is not going to accept any value. This complete
line means that we have declared the main function here. For example a simple calculator takes two or more numbers
from you and returns the result like addition, subtraction, multiplication etc. It may be confusing at this time to understand
the void functionality but in experiment 11 we will discuss it in detail.
{
Following the main function line is a curly bracket which marks the starting of mains body. Always remember that if any
bracket is opened in C language it needs to be closed hence the last line of the above program marks the ending of main
function.
system(“cls”);
This is the first function called inside the main body. All functions will always have a round bracket closing ‘ )’ and a
12
semicolon ‘;’ at their end. In that way we easily recognize the number of functions in a program. According to this rule we
can identify 3 functions in this program. However other properties in different functions may differ but this identity will be
common in all functions. clrscr is short form of clear screen. It clears the screen of any previous output. If not used wont
create any error but output will show all previous compilation result.
retrun 0;
This is the last function of this program. Its name is short form of get character. Its purpose is to get a character. Its used
in last to stop the program until a character is entered. If not used wont show any error but the output will not stop after
compilation. In this case the output is checked manually by pressing Alt+F5 key.
The C program given above will give some compile time errors in Visual Studio. Write following code in the .c file.
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
int main()
{
system("cls");
printf("My First Program");
retrun 0;
}
Save this file (Ctrl + s). Click on the green play icon present on top of the screen to compile and execute your first program.
A black window will appear which is called console. The console will display the output of your program.
Note: There are few functions of old C which is no more available in latest IDEs like clrscr(). Replace clrscr() with
system("cls") and getch() with _getch().
13
Example
Program Output
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int main()
{ My First
system(“cls”); Program
printf("My First Program");
Exercise
Carefully look at the following programs and write the output.
Program Output
#include<stdio.h>
#include<conio.h> My First Program
int main()
{
printf("My First Program");
}
#include<stdio.h>
#include<conio.h>
int main() My First Program
{
printf("My First Program");
}
#include<stdio.h>
#include<conio.h>
int main()
{ My First Program
printf("My First Program");
}
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int main() My First Program
{
system(“cls”);
printf("My First Program");
}
#include<stdio.h>
#include<conio.h>
My First Program
#include<stdlib.h>
int main()
{
system("cls");
printf("My First Program");
}
#include<stdio.h>
#include<conio.h>
#include<stdlib.h> My First Program
int main()
{
system("cls");
printf("My First Program");
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
My First Program
int main()
{
system("cls");
printf("My First
Program");
14
Program Output
#include<stdio.h>
#include<conio.h>
My First Program
#include<stdlib.h>
int main()
{
system(“cls”);
printf("My First Program");
#include<conio.h>
#include<stdio.h> My First Program
#include<stdlib.h>
int main()
{
system(“cls”);
printf("My First Program");
}
#include”conio.h”
#include”stdio.h” My First Program
#include”stdlib.h”
int main()
{
system(“cls”);
printf("My First Program");
}
#include<conio.h>
#include<stdio.h> My First Program
#include<stdlib.h>
main()
{
system(“cls”);
printf("My First Program");
}
#include<CONIO.H>
#include<STDIO.H> My First Program
#include<STDLIB.H>
int main()
{
system(“cls”);
printf("My First Program");
}
Assignment
Write a C program using commands described in this lab to make a resume showing your
complete details.
15
16
Experiment 2 .
Objective
Understanding and Using format specifier and escape sequences with printf.
Theory
The C library functionprintf() sends formatted output to stdout.Following is the declaration for printf() function.
format − This is the string that contains the text to be written to stdout. It can optionally contain embedded format tags that are
replaced by the values specified in subsequent additional arguments and formatted as requested.
Format specifiers are used to substitute and print values inside a printf or scanf statement which are further applicable on
variables. Below is a chart of format specifier examples using printf.
Escape Sequences are used to adjust spacing between lines or characters or the characters themselves.
Example
Program Output
#include<stdio.h>
#include<conio.h>
17
#include<stdlib.h> a
int main()
Iqra University
{
system(“cls”); 20
printf("\n%c",'a');
printf("\n%s","Iqra
printf("\n%d",20); University"); 35.00000
printf("\n%f",35.5);
pri ntf("\n%ld", 1234567);; 1234567
}
#include<stdio.h>
#include<conio.h> a Iqra Univeristy 20 35.00000 1234567
#include<stdlib.h>
int main()
{
system(“cls”);
printf("\n%c %s %d %f %ld",'a',"Iqra University",20,35.5,1234567);
18
Write the output for following programs and give reasons.
Program Output
#include<stdio.h>
#include<conio.h> 97
#include<stdlib.h>
int main() Iqra university
{
system(“cls”);
printf("\n%d",'a'); printf("\n%s","Iqra 35.00000
University"); printf("\n%c",20); 1234567
printf("\n%f",35.5);
pri ntf("\n%ld", 1234567);
retrun 0;
}
Assignment
Write a C program to make your resume with format specifiers and escape sequences showing your complete details.
19
Experiment 3 .
Objective
Studying different data types, variables, variable names, variable declaration, variable definitionand variable initialization.
Theory
Variables are declared by first writing
data types followed by a variable name, e.g.
int a=10;
Here
Supported Example
No. Data Type Syntax format Specifier Value
1 Single Character char %c One character within single quotes char a=’a’;
2 Decimal Integer int %d Any whole number between -32,768 to 32,767 int a=10;
3 Long Integer long int %ld Any number between -2,147,483,648 to 2,147,483,647 long int a=12345;
4 Float float %f Any decimal point number between 10-38 to 1038 float a=1234.567;
0-308
5 Double double %lf Any decimal point number between 1 to 10308 double a=1 23456;
Variable Names
Variable names will always start with an alphabet.
Variable names can contain numbers (1,2,45,66) and underscores (_) but no other special characters (!@#$%^&*).
Variable names cannot resemble to any predefined word e.g. include, printf, getch, scanf etc..
A variable name cannot be used for multiple declarations.
Example
Program Output
a 12 12.500000 If
21
b 13 13.500000 If
Write the output for following programs.
Program Output
Assignment
Write a C program to make a resume showing your complete details using variables.
23