Lab Manual

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

1

110003- Computer Programming and Utilization


Credits: 6 (L=2, P=2)
Practical List
Lab
No.
Experiments
1 Introduction to various hardware components, Microsoft Office & Operating Systems

1. Study of various hardware components like motherboard, RAM, Hard disk,
motherboard slots, different input and output devices.

2. Microsoft Office consists of number of programs like MS-Word, MS-Excel etc
which helps in documentation, making balance sheets, making animated
presentations etc.

3. Operating system is an interface between user and hardware. Its a mean to
communicate with the hardware attached with a computer system (Various
DOS commands like dir, copy, cd, md etc.)

2 C Program has a specific structure, which contains number of sections like
Documentation, Linking, Definition, Global Declaration Section etc.
Functions such as printf( ) and scanf( ) are used to display the output and read the
input respectively which are present in the header file <stdio.h>
Exercise:
Overview of C Programming
Structure of a C program.
How to compile C program?
How to run C program?
1. Write a C program to print HELLO on to the screen.
2. Write a C program to read a number from keyboard and display.
3. Write a C program to calculate area of circle. (Read radius from keyboard)
4. Write a C program to find reminder of two given numbers.

3 Study of Data Types, Operators
Each variable is allocated a specific number of bytes of memory that is identified by
its data type. Some of the common data types are int, float, char, double etc.

1. Write a C program to calculate volume of sphere with radius R.
2. Write a C program to read and display population of the world. (Use long int
and long double)
3. Write a C program to calculate distance covered by an object moving at
velocity V at the end of time T. (V and T are user input)
4. Write a C program to exchange value of two variables.

4 Study of control structures: if, if-else
The if statement is a powerful decision making statement and is used to control the
flow of execution of statements. It is basically a two-way decision statement and is
used in conjunction with an expression.

1. Write a C program to check if a given year is leap year or not. A year is
leap year if it is evenly divisible by 4 and not with 100, but also divisible
by 400.(Use if statement).
2

2. Write a program to check if given number is a positive number or a
negative number (Use if-else statement for the above).
3. Write a program to take a character as an input and display whether it is a
number, alphabet (upper/lower/vowel) or a special character (Use
nested if statement).

5 Switch is again a decision-making statement, which can be used in place of else-if
ladder i.e. when number of conditions to be checked is more.

1. Write a C program for simple calculator (Use if-else ladder and Switch).
2. Write a program to find area for circle, triangle and rectangle.

6 Study of looping structures: for & while
In looping, a sequence of statements is executed until some condition is satisfied
which is placed for termination of the loop. entry-controlled and exit-controlled are
two types of looping structure.
While and for are entry-controlled loop structures, in which the loop will not
be executed if the test condition comes out to be false.

1. Write a program to check whether the given number is prime or not
2. Write a program to compute the sum of the digits of a given integer number.
3. Write a program to find the factorial value of a given number.
4. Write a program to find out the number of digits of a given number.
7
1. Write a c program to read a positive integer number n and generate output
as follows:
If n=5 output: 5 4 3 2 1 0 1 2 3 4 5
If n=6 output: 6 5 4 3 2 1 0 1 2 3 4 5 6
2. Given a number, write a program to reverse the digits of the number. (For
example, the number 12345 should be written as 54321)
3. Write a program to print Fibonacci series. The first seven Fibonacci numbers
are 0, 1, 1, 2, 3, 5, 8.
8 Study of another type of looping structures: do-while
do-while is exit-controlled loop structure, in some situations it might be necessary
to execute the loop, even if the test-condition fails.

1. Write a program to print all the even numbers between 1 to n.
2. Write a C program to evaluate the following series.
3. Sum = 1 + 3 + 5 +.+(2 * n + 1 )
4. Sum = 1
2
3
2
+5
2
7
2
.(2*n+2)
2


9 All these programs will again use any of the looping structure.
* 1 4 3 2 1
* * 2 2 3 2 1
* * * 3 3 3 2 1
* * * * 4 4 4 4 1
3

* *
# # * *
* * * * * *
# # # # * *
*
10 Study of 1-D and 2-D Arrays:
An array is a group of related data items that share a common name. For instance,
we can define an array name salary to represent a set of salaries of a group of
employees.
The ability to use a single name to represent a collection of items and to refer
to an item by specifying the item number enables us to develop concise and efficient
programs.
A list of items can be given one variable name using only one subscript and such a
variable is called a single-subscripted variable or a one-dimensional array.
1. Write a program to find out maximum and minimum from 1-D array.
2. Write a program to sort an integer array in ascending order.
3. Write a program to sort an integer array in descending order.
4. Write a program to search an element in an array, if it is not there then insert
it at the end of the array

11 1. Write a program to add two 3 by 3 matrices.
2. Write a program to multiply two matrices

12 Study of Strings.
A string is an array of characters. Any group of characters defined between double
quotation marks is a constant string. Character strings are often used to build
meaningful and readable programs. A string variable is any valid C variable name.
The general form of declaration of a string variable is
Char string_name[ size ];
The size determines the number of characters in the string-name.
When we initialize a character array by listing its elements, we must supply explicitly
the null terminator.
1. Write a program to scan a string using getchar( ), gets( ), scanf( ),scanf
with editset command(^\n).
2. Write a separate program that will demonstrate the use of strcat( ), strcmp( ),
strcpy( ), strlen( ) functions.
3. Write a program to reverse the string(without using strrev( )).
4. Write a program to count frequency of the last character of a given string in
that string. String will be taken from the user.
13 1. Write a program to concate two strings, compare two strings, copy one string
to another string and find length of the string without using inbuilt string
handling functions.
2. Write a program that would sort a list of strings in the alphabetical order.
4

3. Write a program to replace white spaces by * from a given string.
14 Study of Functions

C functions can be classified into two categories:
1. Library functions : example printf, scanf, sqrt etc
2. User-defined functions: main, developed by the user at the time of writing a
program.
A function is a self-contained block of code that performs a particular task.
In order to make use of a user-defined function, we need to establish three elements
that are related to functions:
1. Function definition
2. Function call
3. Function declaration
Categories of Functions:-
Category 1-Function with no arguments no return value
Category 2-Function with arguments and return value
Category 3-Function with arguments but no return value
Category 4-Function with no argument but return value

1. Write a program for addition of two integer number that will satisfied the
following criteria:
1. Function with no arguments and no return values.
2. Function with arguments and no return values.
3. Function with arguments and one return value.
4. Function with no arguments but return a value.
2. Write a C function to check if given number is prime or not. (Use category 2)

15 1. Write a program that uses a function to sort an array of integers. (Use
category 3)
2. Write a function to scan the string and pass as argument and convert into
opposite case.
3. Write a program to reverse the number. (Use category 4)
e.g.
i/p=12345
o/p=54321
16 Study of Functions and Recursion
Recursion: Recursion is a process in which function calls itself. For example,
main()
{ printf(This is Recursion.);
main();
}
o/p: This is Recursion.
This is Recursion.
1. Write a program to find the Factorial of a given number.
5

2. Write a program to generate Fibonacci series.

17 STRUCTURES AND UNIONS:
An array is a collection of related data elements of same type. Structure can have
elements of different types.
Unions are a concept borrowed from structures and therefore follow the same syntax
as structures. However, there is major distinction between them in terms of storage.
In structures, each member has its own storage location, whereas all the members
of a union use the same location. This implies that, although a union may contain
many members of different types, It can handle only one member at a time.

1. Define a structure data type called time_struct containing three members
integer hour, integer minute, and integer second. Develop a program that
would assign values to the individual members and display the time in this
form: 16:40:51

2. Define a structure called cricket that will describe the following
Information
Player name
Team name
Batting average
Using cricket, declare an array player with 3 elements and write a program to
read the information about all the 3 players and print a team-wise list
containing names of players with their average.

18 1. Design a structure student_record to contain name, roll_no, and total marks
obtained. Develop a program to read data for 10 students in a class and list
them rank-wise.
2. Write a program to demonstrate the use of union.

19 Study of Pointers:

A pointer is a derived data type in C. Pointers contains memory addresses as their
values. Since these memory addresses are the locations in the computer memory
where program instructions and data are stored, pointers can be used to access and
manipulate data stored in the memory.
1. Write a program to show the use of indirection operator * to access the
value pointed by a pointer.
2. Write a program to show the use of pointers in arithmetic operations.

20 Study of OOP (Object Oriented Programming)
Class:- Class is a user-defines data type which contains data members and member
functions to operate on those data members.
Object:-An object is run-time entity in an object-oriented system.

1. Design a simple class with all arithmetic function. Use them in MAIN function.
6

2. Design classes named Triangle, Square, and Circle. Make the different
function in each class to find areas of particular shape.
3. Design a class to find the largest value between the given two numbers.

21 Study of Constructors & Destructors
Constructor: -Constructor is a special member function, which is called
automatically when object is created.
Destructor: -Destructor is used to destroy the objects that have been created by
the constructor.

1. Declare two classes, car and truck, each having speed as private data
member. Define constructor to initialize the data. Define a compare function
to compare speed of car and truck. Define main to show use of above
functions.
2. Declare a class called complex having two float members, real & image to
represent real and imaginary part of a complex number. Define constructor to
initialize two complex numbers and destructor to destroy the objects. Create
member functions to add two complex numbers and to display the results.
Also define main.

22 1. Design a Class having inline function with two arguments to multiply the two
real numbers.
2. Design a Class having private member function division () to divide two
numbers. Use nesting of function to call division ().
3. Declare a class called item having data members item_code and
item_name. Derive a class called details having data members stock_qty,
batch_no and price. Define following functions for above class:
Constructor
Search() to search any item when item_code or batch_no is given.
Update() to update an item when item_code is given.
Display() to display item information.
Main() to declare an object and show the use of above functions.

23 1. Design a class having static data member to count the occurrences of objects.
2. Define a class to represent a bank account. Include members like name of the
account holder, account number, type of account (savings or current) and
balance amount. Define following functions.
To assign initial values to the data members.
To withdraw an amount after checking the balance.
To display the details of the account holder.
Main() to declare an array of objects and show the use of above functions.

24 1. Declare two classes, car and truck, each having speed as private data
member. Define constructor to initialize the data. Define a friend function to
compare speed of car and truck. Define main to show use of above functions.
2. Declare a class called string. Object of this string class represents a character
string. Create objects of string class to perform the addition of two strings
and return the resultant string by object.

You might also like