28 Introduction To Computing
28 Introduction To Computing
7 Input/Output Operators
Be sure that all equipment is properly working before using them for laboratory exercises. Any
defective equipment must be reported immediately to the Lab Engineer or Lab Technical Staff.
Students should keep a safe distance from the circuit breakers, electric circuits or any moving parts
during the experiment.
Avoid any part of your body to be connected to the energized circuit and ground.
Switch off the equipment and disconnect the power supplies from the circuit before leaving the
laboratory.
Make sure that the last connection to be made in your circuit is the power supply and first thing to
be disconnected is also the power supply.
Equipment should not be removed, transferred to any location without permission from the
laboratory staff.
Computer hardware is the collection of physical parts of a computer system. This includes the
computer case, monitor, keyboard, and mouse. It also includes all the parts inside the computer
case, such as the hard disk drive, motherboard, video card, and many others. Computer hardware
is what you can physically touch.
1.2 CPU
Alternately referred to as a processor, central processor, or microprocessor, the CPU (pronounced
sea-pea-you) is the Central Processing Unit of the computer. A computer's CPU handles all
instructions it receives from hardware and software running on the computer.
1.4 Fan
A hardware device that keeps the overall computer or a computer device cool by circulating air to
or from the computer or component. The picture is an example of a fan on a heat sink.
1.5 Motherboard
Alternatively referred to as the mb, mainboard, mboard, mobo, mobd,backplane board, base board,
main circuit board, planar board, system board, or a logic board on Apple computers. The
motherboard is a printed circuit board that is the foundation of a computer, located on the back
side or at the bottom of the computer case. It allocates power and allows communication to the
CPU, RAM, and all other computer hardware components.
1.7 NIC
Short for Network Interface Card, the NIC is also referred to as an Ethernet card and network
adapter. It is an expansion card that enables a computer to connect to a network; such as a home
network, or the Internet using an Ethernet cable with an RJ-45 connector.
1.8 RAM
Alternatively referred to as main memory, primary memory, or system memory, Random Access
Memory (RAM) is a hardware device that allows information to be stored and retrieved on a
computer.
Windows 7 uses a more advanced search index that continuously monitors every file and even the
words within most of your files. When you search for a file or folder in Windows 7, you are much
more likely to find it than you were with Windows Vista or Windows XP.
Open the Start menu and type a search term in the search field at the bottom.
When you locate the file you wanted, double-click it to open it. If you don’t see what you’re
looking for, choose the Folder and Search Options command from the Organize menu to modify
Search settings. You can alter the locations to search, indicate whether to find partial matches for
search terms, and more.
Total Marks: 40
Criteria Level 1 Level 2 Level 3 Level 4
Score
(Max. Marks) 0% ≤ S < 50% 50% ≤ S < 70% 70% ≤ S < 90% 90% ≤ S ≤ 100%
Introduction Very little Introduction is brief Introduction is nearly Introduction complete
(5) background with some minor complete, missing some and well-written;
information mistakes minor points provides all necessary
provided or background principles
information is for the experiment
incorrect
Procedure Many stages of the Many stages of the The procedure could be The procedure is well
(5) procedure are not procedure are entered more efficiently designed and all
entered on the lab on the lab report. designed but most stages stages of the
report. of the procedure are procedure are entered
entered on the lab report. on the lab report.
Data Record Data is brief and Data provides some Data is almost complete Data is complete and
(10) missing significant significant information but has some minor relevant. Tables with
pieces of and has few critical mistakes. units are provided.
information. mistakes. Graphs are labeled.
All questions are
answered correctly.
Data Analysis Data are presented Data are presented in Data are presented in Data are presented in
(10) in very unclear ways (charts, tables, ways (charts, tables, ways (charts, tables,
manner. Error graphs) that are not graphs) that can be graphs) that best
analysis is not clear enough. Error understood and facilitate
included. analysis is included. interpreted. Error understanding and
analysis is included. interpretation. Error
analysis is included.
Report Report contains Report is somewhat Report is well organized Report is well
Quality many errors. organized with some and cohesive but organized and
(10) spelling or grammatical contains some cohesive and contains
errors. grammatical errors. no grammatical errors.
Presentation seems
polished.
Marks Obtained
Objective:
How to write documents in word and the use of editing options available in word.
1. Click on the blue Question Mark to go to Microsoft Office Help. The Office Help is really
good. After opening the help try to search the shortcut key for following tasks in MS Word
2007.
Create a new document of the same type as the current or most recent
document
Open a document
Close a document
Save a document
Desktop Computer
Microsoft Windows operating system, XP or any latest Edition
Microsoft Word 2007
1. Click on start menu > program files>Microsoft Office> Microsoft Word 2007.
This section is designed such a way that you can complete the following tasks independently.
However if there is any ambiguity you can refer it to the lab instructor.
2.5 Templates
Templates are a collection of styles and formatting settings, and they can save you a ton of time
when creating a new document. You can find templates for almost any type of document, from
flyers to resumes, and birthday cards to banners. You can also create your own templates to save
yourself from having to remake documents from scratch.
Go to File menu and click ‘New’. Select Sample templates to use the built-in templates.
Cover Page is the title page of the document. Word 2007 provides a number of preformed cover
pages to give your document a professional look.
To open the Built-in Cover Page Gallery, click the down arrow to the right of Cover Page in
the Pages group on the Insert tab.
1. Scroll down and click the desired cover for the document from the Cover Page Gallery.
Use the scroll bar or scroll arrow to see all the cover page choices.
2. A Cover page will be added to your document.
The fourth group on the Home ribbon is the Style group. Styles are a collection of Formatting
options that you can apply to text. When you use styles to format your document, you can quickly
and easily apply a set of formatting choices consistently throughout your document.
A style is a set of formatting characteristics, such as font name, size, color, paragraph alignment
and spacing. Some styles even include borders and shading. For example, instead of taking three
separate steps to format your heading as 16-point, bold, Cambria, you can achieve the same result
in one step by applying the built-in Heading 1 style. You do not need to remember the
characteristics of the Heading 1 style. For each heading in your document, you just click in the
2.9 Tables
Word provides tables option for placing data in a more formal way.
Click on table in insert tab.
To add Rows and Columns, select top to bottom for rows & left to right for columns
Click to apply when happy with the selection.
Click on the box to enter text.
Observe the new tab opened "Table Tools". You can use this tool to apply further
formatting to your created table.
2.10 Illustrations
Using Illustrations you can add pictures of all types and styles to your document. Followed is detail
Description on how to add illustrations.
2.11 Picture
The first selection in Illustrations is Insert a picture from a file. When you click on this a window
will open for you to browse to a photograph or other picture you have saved on your computer.
Total Marks: 40
Criteria Level 1 Level 2 Level 3 Level 4
Score
(Max. Marks) 0% ≤ S < 50% 50% ≤ S < 70% 70% ≤ S < 90% 90% ≤ S ≤ 100%
Introduction Very little Introduction is brief Introduction is nearly Introduction complete
(5) background with some minor complete, missing some and well-written;
information mistakes minor points provides all necessary
provided or background principles
information is for the experiment
incorrect
Procedure Many stages of the Many stages of the The procedure could be The procedure is well
(5) procedure are not procedure are entered more efficiently designed and all
entered on the lab on the lab report. designed but most stages stages of the
report. of the procedure are procedure are entered
entered on the lab report. on the lab report.
Data Record Data is brief and Data provides some Data is almost complete Data is complete and
(10) missing significant significant information but has some minor relevant. Tables with
pieces of and has few critical mistakes. units are provided.
information. mistakes. Graphs are labeled.
All questions are
answered correctly.
Data Analysis Data are presented Data are presented in Data are presented in Data are presented in
(10) in very unclear ways (charts, tables, ways (charts, tables, ways (charts, tables,
manner. Error graphs) that are not graphs) that can be graphs) that best
analysis is not clear enough. Error understood and facilitate
included. analysis is included. interpreted. Error understanding and
analysis is included. interpretation. Error
analysis is included.
Report Report contains Report is somewhat Report is well organized Report is well
Quality many errors. organized with some and cohesive but organized and
(10) spelling or grammatical contains some cohesive and contains
errors. grammatical errors. no grammatical errors.
Presentation seems
polished.
Marks Obtained
Objective:
How to write documents in excel and the use of editing options available in excel.
1. Copy and paste this data into a newly created Excel File.
2. Now left align the Name column while apply right alignment for the rest of the
columns.
3. Now, use the data of ITP and English to calculate the total marks. To do this use
‘function’, the built in formula in Excel.
Percentage Formula
There are some situations where you need to find some percent of a particular number, marks,
price or the percentage of salary to incremented annually for employees. For all such tasks you
need a percentage formula. We would apply a percentage formula for finding out the
percentage of a student’s marks.
When you would apply the formula you would get the required percentage as shown in figure
30. Percentage is shown in Highlighted column.
Total Marks: 40
Criteria Level 1 Level 2 Level 3 Level 4
Score
(Max. Marks) 0% ≤ S < 50% 50% ≤ S < 70% 70% ≤ S < 90% 90% ≤ S ≤ 100%
Introduction Very little Introduction is brief Introduction is nearly Introduction complete
(5) background with some minor complete, missing some and well-written;
information mistakes minor points provides all necessary
provided or background principles
information is for the experiment
incorrect
Procedure Many stages of the Many stages of the The procedure could be The procedure is well
(5) procedure are not procedure are entered more efficiently designed and all
entered on the lab on the lab report. designed but most stages stages of the
report. of the procedure are procedure are entered
entered on the lab report. on the lab report.
Data Record Data is brief and Data provides some Data is almost complete Data is complete and
(10) missing significant significant information but has some minor relevant. Tables with
pieces of and has few critical mistakes. units are provided.
information. mistakes. Graphs are labeled.
All questions are
answered correctly.
Data Analysis Data are presented Data are presented in Data are presented in Data are presented in
(10) in very unclear ways (charts, tables, ways (charts, tables, ways (charts, tables,
manner. Error graphs) that are not graphs) that can be graphs) that best
analysis is not clear enough. Error understood and facilitate
included. analysis is included. interpreted. Error understanding and
analysis is included. interpretation. Error
analysis is included.
Report Report contains Report is somewhat Report is well organized Report is well
Quality many errors. organized with some and cohesive but organized and
(10) spelling or grammatical contains some cohesive and contains
errors. grammatical errors. no grammatical errors.
Presentation seems
polished.
Marks Obtained
Objective:
How to write documents in power point and the use of editing options available in
power point.
4.2 Slides
4.2.1 New Slide:
1. Click on home ribbon
2. Click on new slide button
3. New slide will be shown in your presentation
4.3 Layout:
Different slide layouts are used to manage the arrangement of content on the side.
Click the layout you want. The layout appears in the slide pane of the PowerPoint window.
1. Make two of the slides as tile slide, third and fourth one as size and content layout and last
one should be blank.
2. Write your name and registration number on first title slide.
3. On second slide write topic as "Computers".
4. Search text from internet and add some points about computers in the successive two slides
and last slide should be having pictures of computers.
4.4 Themes
4.4.1 Applying theme to your slides:
A theme is a set of colors, fonts, and special effects. Themes provide attractive backgrounds
for your PowerPoint slides.
To apply a theme to all of the slides in your presentation:
Choose the Design tab.
Click the More buttons in the Themes group.
Click the design as shown in arrow 3 of figure 18 you want.
Change fonts to Arial, colors to origin and add Metro effects in Design Tab.
4.5 Background:
You can add a dramatic effect to your theme by applying a background.
1. Choose the Design tab.
2. Click the Background Styles button.
3. Click the background you want.
4.5.1 Preview:
Preview: This button previews the animated slides being set by using slide transitions of the
presentation.
4.5.2 Animations:
Animations control how objects move onto, off of, and around your slides. Transitions control how
your presentation moves from one slide to the next
Entrance
An Entrance animation determines the manner in which an object appears on a slide; for
example, an object can move onto a slide.
Emphasis
An Emphasis animation does something to draw attention to an object; for example, the
object can become larger.
Exit
An Exit animation determines the manner in which an object leaves a slide; for example,
an object can move off a slide.
Motion Paths
A Motion Paths animation determines how an object moves around a slide; for example,
an object can move from left to right.
To preview the animation, click the Play button on the Custom Animations pane.
Explore all of them yourself and animate your text and slides. Slide show should display
presentation in effective manner with animations on each slide.
In the pane that contains the Outline and Slides tabs, click the Slides tab.
Select slide thumbnail of the slide that you want to add a sound to.
On the Transitions tab, in the Timing group, click the arrow next to Sound, and then do
one of the following:
1. To add a sound from the list, select the sound that you want.
2. To add a sound not found on the list, select Other Sound, locate the sound file that
you want to add, and then click OK.
1. All slides should advance one by one at mouse click or keyboard keys.
Proper Layout
Theme
Background
Animation
Transition Sound
Transition Speed
Tables
And all other effects which you learn in this lab.
Total Marks: 40
Criteria Level 1 Level 2 Level 3 Level 4
Score
(Max. Marks) 0% ≤ S < 50% 50% ≤ S < 70% 70% ≤ S < 90% 90% ≤ S ≤ 100%
Introduction Very little Introduction is brief Introduction is nearly Introduction complete
(5) background with some minor complete, missing some and well-written;
information mistakes minor points provides all necessary
provided or background principles
information is for the experiment
incorrect
Procedure Many stages of the Many stages of the The procedure could be The procedure is well
(5) procedure are not procedure are entered more efficiently designed and all
entered on the lab on the lab report. designed but most stages stages of the
report. of the procedure are procedure are entered
entered on the lab report. on the lab report.
Data Record Data is brief and Data provides some Data is almost complete Data is complete and
(10) missing significant significant information but has some minor relevant. Tables with
pieces of and has few critical mistakes. units are provided.
information. mistakes. Graphs are labeled.
All questions are
answered correctly.
Data Analysis Data are presented Data are presented in Data are presented in Data are presented in
(10) in very unclear ways (charts, tables, ways (charts, tables, ways (charts, tables,
manner. Error graphs) that are not graphs) that can be graphs) that best
analysis is not clear enough. Error understood and facilitate
included. analysis is included. interpreted. Error understanding and
analysis is included. interpretation. Error
analysis is included.
Report Report contains Report is somewhat Report is well organized Report is well
Quality many errors. organized with some and cohesive but organized and
(10) spelling or grammatical contains some cohesive and contains
errors. grammatical errors. no grammatical errors.
Presentation seems
polished.
Marks Obtained
Objective:
All the tools needed to make flowcharts in MS Word 2013 lie with the Drawing Tools. But first
do these three preliminary steps:
Collapse the Ribbon by clicking the little upward arrow (or Click Ctrl+F1) on the extreme right so
only the tab names show.
Click the View tab and click the Gridlines checkbox. The grid helps you align and size the
flowchart symbols precisely as you can snap them to the gridlines. You can also customize the
gridlines (Page Layout — Arrange — Align — Grid Settings).
Now, let’s start the meticulous job of inserting our shapes and connecting them all together. It
always helps if you map it out on paper first, and then use Word to give it the finished look. A
rough sketch helps you understand the page layout on Word to begin with. The process is simple
but putting some planning into using this “planning tool” is a timesaver. All the required symbols
can be found on the Insert tab – Shapes. Click the dropdown for Shapes.
1. The recommended way is to do it right the first time. Use the gridlines and draw them with
uniform widths when you are placing them on the canvas.
2. Click on individual shapes and drag them to the new locations. If you have many shapes,
this can be very time consuming. The gridlines help you snap them in place.
3. Select all the shapes you want to align. On the Format tab, click the Align dropdown menu.
Select Align Selected Objects and use the alignment tool to align the shapes automatically.
After the flowchart has been laid out, you can neatly align the diagram according to the page.
1. Group all the shapes and connectors. Select all the shapes and connectors. On the Format
tab, click the Group dropdown and select Group.
2. From the Align dropdown check if the Align to Margin item is selected. Then, click Align
Center and/or Align Middle.
3. Optionally, resize the canvas by dragging the corner or edges.
The colorful flowchart you see above is nothing but a more formatted flowchart. Formatting a
flowchart should be the final stage after you have inserted, connected, and labelled all the boxes.
It is better to do it in bulk rather than putting the flourishes on individual boxes as you go along.
So, select multiple shapes and format them together.
I will leave it to your creative eye, and just point you to the basic tools you can access from the
Format tab on the Ribbon or the more detailed options available on the side panel. Open the side
panel by right-clicking on a shape and selecting Format Shape.
You have many options available to design the shapes and the connectors:
Shape Styles: A quick way to add color or gradient fills to the shapes.
Shape Fills: Use your choice of solid colors or gradients. Don’t use too many color
schemes.
Shape Outlines: Set the visual properties of the bounding lines. Also, use it to make the
connector arrows thicker or thinner.
Effects: Give the shapes depth with 3-Dimensions, Shadows etc.
As you can see, there are many options to add a variety of finishing touches to the barebones
flowchart. It is painstaking, but do fuss over it if you want a thoroughly professional look.
The biggest difference between Word and Visio is that Visio is designed to make flowcharts and
drawings where as word is a text editing software. This makes it very easy to maneuver and make
changes in Visio according to one’s requirements.
After selecting “Basic Diagram”, a new window appears where all the shapes are neatly arranged on the
left side under the tab of “Basic Shapes”.
Display the Grid by using the same method as used in Word. Drop all the shapes in the Work Space.
Colors can be added to shapes and formatted as same as in word by using format or simply by “Styles
Option”. Right click the shape you want to edit in the Work Space and select “Styles” to open a variety of
editing options.
Flow Chart I
Figure 5-15.
. Flow Chart II
Department of Electrical Engineering
65
Lab Exercise and Summary
Total Marks: 40
Criteria Level 1 Level 2 Level 3 Level 4
Score
(Max. Marks) 0% ≤ S < 50% 50% ≤ S < 70% 70% ≤ S < 90% 90% ≤ S ≤ 100%
Introduction Very little Introduction is brief Introduction is nearly Introduction complete
(5) background with some minor complete, missing some and well-written;
information mistakes minor points provides all necessary
provided or background principles
information is for the experiment
incorrect
Procedure Many stages of the Many stages of the The procedure could be The procedure is well
(5) procedure are not procedure are entered more efficiently designed designed and all stages
entered on the lab on the lab report. but most stages of the of the procedure are
report. procedure are entered on entered on the lab
the lab report. report.
Data Record Data is brief and Data provides some Data is almost complete Data is complete and
(10) missing significant significant information but has some minor relevant. Tables with
pieces of and has few critical mistakes. units are provided.
information. mistakes. Graphs are labeled. All
questions are answered
correctly.
Data Analysis Data are presented in Data are presented in Data are presented in Data are presented in
(10) very unclear ways (charts, tables, ways (charts, tables, ways (charts, tables,
manner. Error graphs) that are not graphs) that can be graphs) that best
analysis is not clear enough. Error understood and facilitate
included. analysis is included. interpreted. Error understanding and
analysis is included. interpretation. Error
analysis is included.
Report Report contains Report is somewhat Report is well organized Report is well
Quality many errors. organized with some and cohesive but contains organized and
(10) spelling or grammatical some grammatical errors. cohesive and contains
errors. no grammatical errors.
Presentation seems
polished.
Marks Obtained
6.2 Perform the following steps to setup the IDE for C programming.
Create a new project by clicking File->New->Project.
From Installed Template choose other language
Choose language Visual C++
In Visual C++ choose tab Win32
Choose project type Win32 Console Application and then click OK
After clicking Finish you will find a project has been created with below structure. Open solution
explorer to see the structure
To start programming, right click on Source Files and add a new item. You need
to make sure below two points,
Select C++ File to add
Preprocessor Commands
Functions
Variables
Statements & Expressions
Comments
#include <stdio.h>
int main()
{
/* My first program */
printf("Hello, World! \n");
return 0;
}
6.3.2 Functions:
Functions are main building blocks of any C Program. Every C Program will have one
or more functions and there is one mandatory function which is called main() function.
This function is prefixed with keyword int which means this function returns an integer
value when it exits. This integer value is returned using return statement.
6.3.3 Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You will
learn in detail about variables in next topics
6.3.5 Comments:
Comments are used to give additional useful information inside a C Program. All the
comments will be put inside /*...*/ as given in the example above. A comment can span
through multiple lines.
C is a case sensitive programming language. It means in C printf and Printf will have
different meanings.
Department of Electrical Engineering
74
Activity 01:-
Type the following program in C Editor and execute it. Mention the Error.
void main(void)
{
printf(“Hello World”);
}
Activity 02:-
Add the following line at the beginning of the above program. Recompile
the program. What is the output?
#include<stdio.h>
Activity 03:-
Make the following changes to the program. What Errors are observed?
i. Write Void instead of void
6.5 Variables:
A variable is just a named area of storage that can hold a single value (numeric or
character). The C language demands that you declare the name of each variable that
you are going to use and its type.
Local Variables
Global Variables
For example, if you want to declare a variable of type integer then the syntax will be
int number;
6.7 Input:
Any programming language input means to feed some data into program. This can be
given in the form of file or from command line. C programming language provides a set
of built-in functions to read given input and feed it to the program as per requirement.
%d => integer
%c => character
%f => float etc.
6.11 Operators
There are various types of operators that may be placed in three categories:
Arithmetic + - * / %
Assignment = += -= *= /= %=
Relational < > <= >= == !=
Logical && , || , !
Department of Electrical Engineering
77
Activity 04:-
Write five statements by using printf function to print the asterisk pattern:
*****
*****
*****
*****
*****
Solution:
printf("*****");
Copy and paste the line five times and then compile the code.
Activity 05:-
Write program that print the following shape on console:
*************
* *
* *
* *
*************
Activity 06:-
Write a C program to declare two integer and one float variables then initialize them to 10,
15, and 12.6 then prints these values on the screen.
Solution:
Total Marks: 40
Criteria Level 1 Level 2 Level 3 Level 4
Score
(Max. Marks) 0% ≤ S < 50% 50% ≤ S < 70% 70% ≤ S < 90% 90% ≤ S ≤ 100%
Introduction Very little Introduction is brief Introduction is nearly Introduction complete
(5) background with some minor complete, missing some and well-written;
information mistakes minor points provides all necessary
provided or background principles
information is for the experiment
incorrect
Procedure Many stages of the Many stages of the The procedure could be The procedure is well
(5) procedure are not procedure are entered more efficiently designed designed and all stages
entered on the lab on the lab report. but most stages of the of the procedure are
report. procedure are entered on entered on the lab
the lab report. report.
Data Record Data is brief and Data provides some Data is almost complete Data is complete and
(10) missing significant significant information but has some minor relevant. Tables with
pieces of and has few critical mistakes. units are provided.
information. mistakes. Graphs are labeled. All
questions are answered
correctly.
Data Analysis Data are presented in Data are presented in Data are presented in Data are presented in
(10) very unclear ways (charts, tables, ways (charts, tables, ways (charts, tables,
manner. Error graphs) that are not graphs) that can be graphs) that best
analysis is not clear enough. Error understood and facilitate
included. analysis is included. interpreted. Error understanding and
analysis is included. interpretation. Error
analysis is included.
Report Report contains Report is somewhat Report is well organized Report is well
Quality many errors. organized with some and cohesive but contains organized and
(10) spelling or grammatical some grammatical errors. cohesive and contains
errors. no grammatical errors.
Presentation seems
polished.
Marks Obtained
Objective:
int integer2;
integer2 = 90;
Format type can be: %d,%c,%f or others, as we learned before for printf statement.
7.4.1 Example:
scanf( "%d ",&v1);
scanf("%d", &number);
// A program that get 2 numbers from user and print their sum
#include < stdio.h > // I/O standard library in C
int main () //must be first statement in C/C++ program
{
int number1;
int number2;
int sum = 0;
printf ("Enter num 1 = " );
Solution:
Step 1:
Declare three integer variables num1 and num2 and result in main function
Step 2:
Test input:
Enter num1: 12
Enter num2: 4
Result = 16
Activity 02:-
Write a program that gets two integer numbers from user. Your program should
perform subtraction multiplication and division on both number and display result on
console.
𝒂 𝒅+𝒆
∗𝒄+
𝒃 𝒇
Activity 04:-
Write program for the following flow chart
Total Marks: 40
Criteria Level 1 Level 2 Level 3 Level 4
Score
(Max. Marks) 0% ≤ S < 50% 50% ≤ S < 70% 70% ≤ S < 90% 90% ≤ S ≤ 100%
Introduction Very little Introduction is brief Introduction is nearly Introduction complete
(5) background with some minor complete, missing some and well-written;
information mistakes minor points provides all necessary
provided or background principles
information is for the experiment
incorrect
Procedure Many stages of the Many stages of the The procedure could be The procedure is well
(5) procedure are not procedure are entered more efficiently designed designed and all stages
entered on the lab on the lab report. but most stages of the of the procedure are
report. procedure are entered on entered on the lab
the lab report. report.
Data Record Data is brief and Data provides some Data is almost complete Data is complete and
(10) missing significant significant information but has some minor relevant. Tables with
pieces of and has few critical mistakes. units are provided.
information. mistakes. Graphs are labeled. All
questions are answered
correctly.
Data Analysis Data are presented in Data are presented in Data are presented in Data are presented in
(10) very unclear ways (charts, tables, ways (charts, tables, ways (charts, tables,
manner. Error graphs) that are not graphs) that can be graphs) that best
analysis is not clear enough. Error understood and facilitate
included. analysis is included. interpreted. Error understanding and
analysis is included. interpretation. Error
analysis is included.
Report Report contains Report is somewhat Report is well organized Report is well
Quality many errors. organized with some and cohesive but contains organized and
(10) spelling or grammatical some grammatical errors. cohesive and contains
errors. no grammatical errors.
Presentation seems
polished.
Marks Obtained
Objective:
if (number<0)
number= -1 * number;
if (marks>50)
printf(”Passed”);
else
printf(“failed”);
You can use as many if-statements after the else part, for example, consider the following code:
if (marks>90)
printf(“Grade is A”);
else if (marks>85)
printf(“Grade is B”);
The above statement will output the grade “A” for all students scoring more than 90 marks.
However, the grade of the students will be B who have scored more than 85 marks and less than
90, similarly, the remaining students will get F grade. The statement will be executed in a way that
first statement will be checked, if the students marks are greater than 90, then the grade will be
shown as “A” and the remaining parts will not be executed (The else part). If the students marks
are less than 90, then the first statement would be evaluated as false, and the control will be passed
to the else if (marks >85) statement.
if (marks>90)
printf(”Grade is A”);
printf(”congratulations, you have performed excellent”);
If the marks are more than 90, the program will display the following output:
Grade is A
Congratulations, you have performed excellent
However, suppose if the marks are less than 90, then guess what you will get:
Nothing ….
This is due to the fact that c++ considers only one statement as associated with the condition, and
the statement
is not part of the if-statement, and as the if has been evaluated as false therefore the above statement
will be executed
if (marks>90)
{
printf(”Grade is A”);
printf(”congratulations, you have performed excellent”);
}
Now both statements will be associated with the if-statement. In case the if-statement is false, none
of the above statements will be executed.
if num1 is greater then num2 then print num1 is greater then num2
if num2 is greater then num1 then print num2 is greater then num1
Total Marks: 40
Criteria Level 1 Level 2 Level 3 Level 4
Score
(Max. Marks) 0% ≤ S < 50% 50% ≤ S < 70% 70% ≤ S < 90% 90% ≤ S ≤ 100%
Introduction Very little Introduction is brief Introduction is nearly Introduction complete
(5) background with some minor complete, missing some and well-written;
information mistakes minor points provides all necessary
provided or background principles
information is for the experiment
incorrect
Procedure Many stages of the Many stages of the The procedure could be The procedure is well
(5) procedure are not procedure are entered more efficiently designed designed and all stages
entered on the lab on the lab report. but most stages of the of the procedure are
report. procedure are entered on entered on the lab
the lab report. report.
Data Record Data is brief and Data provides some Data is almost complete Data is complete and
(10) missing significant significant information but has some minor relevant. Tables with
pieces of and has few critical mistakes. units are provided.
information. mistakes. Graphs are labeled. All
questions are answered
correctly.
Data Analysis Data are presented in Data are presented in Data are presented in Data are presented in
(10) very unclear ways (charts, tables, ways (charts, tables, ways (charts, tables,
manner. Error graphs) that are not graphs) that can be graphs) that best
analysis is not clear enough. Error understood and facilitate
included. analysis is included. interpreted. Error understanding and
analysis is included. interpretation. Error
analysis is included.
Report Report contains Report is somewhat Report is well organized Report is well
Quality many errors. organized with some and cohesive but contains organized and
(10) spelling or grammatical some grammatical errors. cohesive and contains
errors. no grammatical errors.
Presentation seems
polished.
Marks Obtained
Objective:
if (percentage>=70 )
if (age <16)
The nested-if statement is executed in the following way, first, the statement (percentage>=70 )
will be evaluated, if the statement is true then the control is passed to the first statement within this
if-statement. The first line within this if-statement is again an if-statement, now the statement (age
<16) will be evaluated. Here if this statement is also true, then the student will be given the
scholarship. We can use logical-and to solve the same problem as well. This will be discussed in
the next section.
To understand the above statement, revise your concepts from the previous course of ITC. The
logical-and is evaluated as true if both values (conditions) are true. For revision, you can have a
look on the Appendix A. For the above code, if both conditions are true, then the statement will be
executed. The difference between using logical-and and nested-if has been explained in the next
section.
9.3 Similarities and Differences for the use of nested-if and logical-and
For the example used in the section 4.1 and 4.2, there is no difference, one can use any of them
(nested-if or logical-and)
9.3.1.1 Code A:
if (percentage>=70 )
if (age <16)
9.3.1.2 Code B:
if (percentage>=70 && age <16)
In this scenario, both codes will output the same. However, there are certain differences in using
nested-if and logical-and (&&). There are some scenarios where use of nested-if is better, however,
there are some other scenarios where the use of logical-and(&&) is better. For example, consider
the following case.
if (percentage>=70 )
if (age <16)
However, you probably, will not like to write the above code in the following way.
if (percentage>=70)
else
if (percentage>=70 )
if (age <16)
else
The “printf” statement will be executed if any of the conditions is true. For example either the
person has achieved more than 70% marks or his/her age is less than 16, the scholarship will be
awarded to that person.
Department of Electrical Engineering
110
9.5 Logical-not (!)
The logical-not (!) is used before any condition and it will reverse the evaluation of the condition.
For example, if the condition is true, the logical-not (!) will make it false, if the condition is false,
then the logical-not (!) will make it true. Consider the following example. logical-not (!):
if (!(5==5))
the above statement will be evaluated as false because the condition (5==5) is evaluated as true
and logical-not (!) will make it false, as the if-statement is evaluated as false, therefore, the printf-
statement will not be executed. Similarly, we have written the previously discussed example by
incorporating logical-not (!)
Now we have both logical-and and logical-not. You know that logical-and will be evaluated as
true if both conditions are true. The first condition would be true when percentage is more than or
equal to 70, however, the second condition would be true when the age is more than or equal to
16. Remember, from previous discussion that whenever the inner condition (age<16) is false, the
logical-not (!) will make it true. Therefore, the scholarship will be given to only those students
whose percentage is greater than or equal to 70 and whose age is more than or equal to 16.
Activity 02:-
Write a C program to find whether the given input is a vowel or not using logical
operators.
Total Marks: 40
Criteria Level 1 Level 2 Level 3 Level 4
Score
(Max. Marks) 0% ≤ S < 50% 50% ≤ S < 70% 70% ≤ S < 90% 90% ≤ S ≤ 100%
Introduction Very little Introduction is brief Introduction is nearly Introduction complete
(5) background with some minor complete, missing some and well-written;
information mistakes minor points provides all necessary
provided or background principles
information is for the experiment
incorrect
Procedure Many stages of the Many stages of the The procedure could be The procedure is well
(5) procedure are not procedure are entered more efficiently designed designed and all stages
entered on the lab on the lab report. but most stages of the of the procedure are
report. procedure are entered on entered on the lab
the lab report. report.
Data Record Data is brief and Data provides some Data is almost complete Data is complete and
(10) missing significant significant information but has some minor relevant. Tables with
pieces of and has few critical mistakes. units are provided.
information. mistakes. Graphs are labeled. All
questions are answered
correctly.
Data Analysis Data are presented in Data are presented in Data are presented in Data are presented in
(10) very unclear ways (charts, tables, ways (charts, tables, ways (charts, tables,
manner. Error graphs) that are not graphs) that can be graphs) that best
analysis is not clear enough. Error understood and facilitate
included. analysis is included. interpreted. Error understanding and
analysis is included. interpretation. Error
analysis is included.
Report Report contains Report is somewhat Report is well organized Report is well
Quality many errors. organized with some and cohesive but contains organized and
(10) spelling or grammatical some grammatical errors. cohesive and contains
errors. no grammatical errors.
Presentation seems
polished.
Marks Obtained
Objective:
switch (expression)
case value1:
statements……
break;
case value2:
statements..….
break;
case value n:
statements
break;
default:
statements….
break;
The expression sometimes, is referred to, selector. First the expression in the switch statement is
evaluated. Subsequently, the corresponding case is executed. It is not mandatory that the
expression is an identifier. It can be a identifier or an expression. However, the value of the
expression should be integral only.
In such a menu driven statement, using switch statement is encouraged. This will make your code
more readable. You can program this problem using the following code:
int option;
scanf ("%d",&option);
switch (option)
case 1:
break;
case 2:
break;
case 3:
break;
default:
break;
When user enters the value 1, the user will get the following output:
When user enters the value 2, the user will get the following output:
When user enters the value 3, the user will get the following output:
int option;
switch (option)
case 1:
case 2:
case 3:
default:
When user enters the value 2, the user will get the following output:
When user enters the value 3, the user will get the following output:
When the break statement is not included then from onward a true case, all cases will be executed
until the switch statements ends, or a break occurs. For example consider the following example,
for more clarification.
int option;
switch (option)
case 1:
break;
case 3:
default:
In this switch statement, we have written a break statement after the statement associated
with case 2.
When user enters the value 1, the user will get the following output:
The user will not get the output You selected the option to see the profit statement
because there is a break after second case.
When user enters the value 2, the user will get the following output:
Finally, when user enters the value 3, the user will get the following output:
If user enters any statement other than 1, 2, or 3 (for which we have written cases), in that case,
the default statement is executed.
char option;
scanf("%d", &option);
switch(option)
case ‘E’:
break;
case ‘D’:
break;
case ‘R’:
break;
default:
printf("Wrong input”);
1) For the character value, you need to enclose it in a singe quotation mark.
2) The program will work fine for the upper case characters only. If user enter “d” in
lowercase rather than upper case, then the program will output “printf"”Wrong input”;”.
To tackle both uppercase and lowercase character, you can write the following code:
switch(option)
case ‘E’:
case ‘e’:
break;
case ‘D’:
case ‘d’:
case ‘R’:
case ‘r’:
break;
default:
printf("Wrong input”);
For the better understanding of this program, remember, the discussion on the break statement in
the previous section.
int marks;
scanf("%d",&marks);
switch(marks>=50)
case 1:
break;
case 0:
break;
In this case, the expression will be evaluated as logical-true or logical-false. If the marks
are greater than or equal to 50, then the statement “ printf"”Congratulations, you have
qualified the examination”; will be executed, otherwise, the statement “ printf"”Sorry, you
have not qualified the examination ”; will be executed. As the expression is logical-true or
logical-false, therefore, you can use “true” instead of 1 and “false” instead of 0 as shown below.
int marks;
scanf("%d",&marks);
switch(marks>=50)
case true:
break;
case false:
break;
int value;
scanf("%d",&value);
switch (value%10)
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
break;
Activity 02:-
Write a program which asks the user to enter number of days. Subsequently, the
user can either select any of the following options:
Based on the option entered by user, your program should calculate and display
the results accordingly.
Activity 03:-
Write a program which will read two numbers and would display the following menu to the
user:
Note: All the above operations would be applied on both the numbers that user reads.
Total Marks: 40
Criteria Level 1 Level 2 Level 3 Level 4
Score
(Max. Marks) 0% ≤ S < 50% 50% ≤ S < 70% 70% ≤ S < 90% 90% ≤ S ≤ 100%
Introduction Very little Introduction is brief Introduction is nearly Introduction complete
(5) background with some minor complete, missing some and well-written;
information mistakes minor points provides all necessary
provided or background principles
information is for the experiment
incorrect
Procedure Many stages of the Many stages of the The procedure could be The procedure is well
(5) procedure are not procedure are entered more efficiently designed designed and all stages
entered on the lab on the lab report. but most stages of the of the procedure are
report. procedure are entered on entered on the lab
the lab report. report.
Data Record Data is brief and Data provides some Data is almost complete Data is complete and
(10) missing significant significant information but has some minor relevant. Tables with
pieces of and has few critical mistakes. units are provided.
information. mistakes. Graphs are labeled. All
questions are answered
correctly.
Data Analysis Data are presented in Data are presented in Data are presented in Data are presented in
(10) very unclear ways (charts, tables, ways (charts, tables, ways (charts, tables,
manner. Error graphs) that are not graphs) that can be graphs) that best
analysis is not clear enough. Error understood and facilitate
included. analysis is included. interpreted. Error understanding and
analysis is included. interpretation. Error
analysis is included.
Report Report contains Report is somewhat Report is well organized Report is well
Quality many errors. organized with some and cohesive but contains organized and
(10) spelling or grammatical some grammatical errors. cohesive and contains
errors. no grammatical errors.
Presentation seems
polished.
Marks Obtained
Objective:
To achieve this, you know that you can write 10 statements in the following manner:
However, this is not elegant way to achieve this task, although the above statements will produce
the required output.
You can notice that the statement Printf(” Welcome to Cp Course\n”); is repeating 10 times.
This type of statements can be written using a loop. For example, consider the following code
which will print the same output:
for(int i=1;i<=10;i++)
printf(”Welcome to Cp Course\n”);
for(int i=1;i<=20;i++)
printf(”Welcome to Cp Course\n”);
How this program works, we will learn in the following sections. We will start formally describing
loops. The loops can be categorized into two major types such as: Pre-condition loops and post-
condition loops
11.1.1.1 For-Loop
Consider the code written in the previous section
for(int i=1;i<=20;i++)
printf(”Welcome to Cp Course\n”);
This loop is called for-loop. This loop has initialization such as int i=1 from where the loop is
going to be started. Then after semi-colon, there is a condition i<=20, and then the increment i++.
The working of this loop will be as follows:
a) If we want to associate another statement with loop, then we must enclose the
statements in brackets, otherwise only the first statement will be considered as associated
with the loop. This is similar concept which you have learned in if-statements. For
example, for compound statements, we will write the loop in the following way:
for(int i=1;i<=20;i++)
Printf(”Hello class”);
b) The initialization statement and increment statements are optional to within the loop
brackets. For example, you can write the same code in the following way:
int i=1;
for(;i<=20;)
Printf(”Hello class”);
i++;
c) The increment in the above code need not to be the increment, it could be decrement
as well. For example the same code can be rewritten as follows:
for(;i>=1;)
printf(”Hello class”;
i--;
We have used decrement instead of increment. This means we have counted the loop from
20 towards However, please note, we have also changed the condition as well. Now we
are starting loop from 20 and need to execute statements until the i remains greater of
equal to 1.
d) If we start a loop from 20 and do not change the condition, then guess what will
happen.
int i=20;
for(;i<=20;)
Printf(”Hello class”);
i--;
Clearly observe that we have started a loop from 20 and decrement the condition variable I, this
will become 19, 18, 17… and so on, and our conditions is that repeat this loop until i remains less
than or equal to 20. The next numbers 19, 18, 17, … and so on will always remain smaller than
There are different categories of controlling a loop. The for-loop comes under the category of
counter-controlled loop. You will learn about many different categories of controlling the
conditions of the loop in the next section where we will discuss the while loop.
Activity 01:-
Write a program to print “Hello word” ten times using for loop.
Activity 02:-
Write a program that get a number num from user and print the “Hello word”
num times.
Activity 03:-
Write a program that get a number num from user and print the integers from
0 to num using for loop.
Activity 04:-
Write a program that get a number num from user and print the even integers
from 0 to num using for loop.
Activity 05:-
Write a program that calculates the sum of integers from 0 to num using for
loop. Num should be entered by the user.
Activity 06:-
Write a program that print table of 2 from 1 to 20 by using For loop.
Total Marks: 40
Criteria Level 1 Level 2 Level 3 Level 4
Score
(Max. Marks) 0% ≤ S < 50% 50% ≤ S < 70% 70% ≤ S < 90% 90% ≤ S ≤ 100%
Introduction Very little Introduction is brief Introduction is nearly Introduction complete
(5) background with some minor complete, missing some and well-written;
information mistakes minor points provides all necessary
provided or background principles
information is for the experiment
incorrect
Procedure Many stages of the Many stages of the The procedure could be The procedure is well
(5) procedure are not procedure are entered more efficiently designed designed and all stages
entered on the lab on the lab report. but most stages of the of the procedure are
report. procedure are entered on entered on the lab
the lab report. report.
Data Record Data is brief and Data provides some Data is almost complete Data is complete and
(10) missing significant significant information but has some minor relevant. Tables with
pieces of and has few critical mistakes. units are provided.
information. mistakes. Graphs are labeled. All
questions are answered
correctly.
Data Analysis Data are presented in Data are presented in Data are presented in Data are presented in
(10) very unclear ways (charts, tables, ways (charts, tables, ways (charts, tables,
manner. Error graphs) that are not graphs) that can be graphs) that best
analysis is not clear enough. Error understood and facilitate
included. analysis is included. interpreted. Error understanding and
analysis is included. interpretation. Error
analysis is included.
Report Report contains Report is somewhat Report is well organized Report is well
Quality many errors. organized with some and cohesive but contains organized and
(10) spelling or grammatical some grammatical errors. cohesive and contains
errors. no grammatical errors.
Presentation seems
polished.
Marks Obtained
Objective:
To achieve this, you know that you can write 10 statements in the following manner:
int i=1;
while(;i<=20;)
Printf(”Hello class”);
This loop is executed in the similar way as discussed previously about for-loop. This type of loop
is called counter controlled loop. However, there are some other types of controlling a loop.
int marks;
int sum=0;
const int sentinel=-1; /// the marks of a student can not be negative.
Scanf(“%d”,&marks);
while(marks!=sentinel)
sum=sum+marks;
Scanf(“%d”,&marks);
Activity 01:-
Write a program to print “Hello word” ten times using while loop.
Activity 02:-
Write a program that get a number num from user and print the “Hello
word” num times.
Activity 03:-
Write a program that get a number num from user and print the integers
from 0 to num using while loop.
Activity 04:-
Write a program that get a number num from user and print the even
integers from 0 to num using while loop.
Activity 05:-
Write a program that calculates the sum of integers from 0 to num using while
loop. Num should be entered by the user.
Activity 06:-
Write a program that print table of 2 from 1 to 20 by using While loop.
Activity 7.1:-
#include <stdio.h>
main()
{
int count=1;
while (count <=4)
{
printf("%d ", count);
count++;
}
}
Activity 7.2:-
#include <stdio.h>
main()
{
int var=1;
while (var <=2)
{
printf("%d ", var);
}
}
#include <stdio.h>
int main()
{
int var =6;
while (var >=5)
{
printf("%d", var);
var++;
}
return 0;
}
Activity 7.4:-
#include <stdio.h>
int main()
{
int var =5;
while (var <=10)
{
printf("%d", var);
var--;
}
return 0;
}
main()
{
int i = 10;
while ( i > 0 )
{
printf("Hello %d\n", i );
i = i -1;
if( i == 6 )
{
break;
}
}
}
int i=1;
do {
cout<<” Welcome to Cp Course\n”;
cout<<”Hello class”;
i++;
} while(i<=20);
Activity 08:-
Write a program to print “Hello word” ten times using do while loop.
Activity 09:-
Write a program that get a number num from user and print the “Hello
word” num times.
Activity 10:-
Write a program that get a number num from user and print the integers
from 0 to num using do while loop.
Activity 11:-
Write a program that get a number num from user and print the even
integers from 0 to num using do while loop.
Activity 12:-
Write a program that calculates the sum of integers from 0 to num using while
loop. Num should be entered by the user.
Department of Electrical Engineering
149
Activity 13:-
Write a program that print table of 2 from 1 to 20 by using Do-While loop.
Activity 14:-
Write the output of the following programs.
Activity 14.1:-
#include <stdio.h>
main()
{
int i = 10;
do{
printf("Hello %d\n", i );
i = i -1;
}while ( i > 0 );
}
main()
{
int i = 10;
do{
printf("Hello %d\n", i );
i = i -1;
if( i == 6 )
{
break;
}
}while ( i > 0 );
}
Total Marks: 40
Criteria Level 1 Level 2 Level 3 Level 4
Score
(Max. Marks) 0% ≤ S < 50% 50% ≤ S < 70% 70% ≤ S < 90% 90% ≤ S ≤ 100%
Introduction Very little Introduction is brief Introduction is nearly Introduction complete
(5) background with some minor complete, missing some and well-written;
information mistakes minor points provides all necessary
provided or background principles
information is for the experiment
incorrect
Procedure Many stages of the Many stages of the The procedure could be The procedure is well
(5) procedure are not procedure are entered more efficiently designed designed and all stages
entered on the lab on the lab report. but most stages of the of the procedure are
report. procedure are entered on entered on the lab
the lab report. report.
Data Record Data is brief and Data provides some Data is almost complete Data is complete and
(10) missing significant significant information but has some minor relevant. Tables with
pieces of and has few critical mistakes. units are provided.
information. mistakes. Graphs are labeled. All
questions are answered
correctly.
Data Analysis Data are presented in Data are presented in Data are presented in Data are presented in
(10) very unclear ways (charts, tables, ways (charts, tables, ways (charts, tables,
manner. Error graphs) that are not graphs) that can be graphs) that best
analysis is not clear enough. Error understood and facilitate
included. analysis is included. interpreted. Error understanding and
analysis is included. interpretation. Error
analysis is included.
Report Report contains Report is somewhat Report is well organized Report is well
Quality many errors. organized with some and cohesive but contains organized and
(10) spelling or grammatical some grammatical errors. cohesive and contains
errors. no grammatical errors.
Presentation seems
polished.
Marks Obtained