CP Lab Report # 5

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

AIR UNIVERSITY

DEPARTMENT OF ELECTRICAL AND COMPUTER


ENGINEERING
LAB TITLE: While and Do…While Loops In C++ (LAB # 05)

Student Name: Taimoor Ahmed Reg. No: 191881

Objective: To learn and properly use while and Do…while loops when writing a
C++ program.

LAB ASSESSMENT:

Excellent Good Average Satisfactory Unsatisfactory


Attributes
(5) (4) (3) (2) (1)
Ability to Conduct
Experiment
Ability to assimilate the
results
Effective use of lab
equipment and follows
the lab safety rules

Total Marks: Obtained Marks:

LAB REPORT ASSESSMENT:


Excellent Good Average Satisfactory Unsatisfactory
Attributes
(5) (4) (3) (2) (1)

Data presentation

Experimental results

Conclusion

Total Marks: Obtained Marks:

Date: Signature:
AIR UNIVERSITY
DEPARTMENT OF ELECTRICAL AND COMPUTER
ENGINEERING
LAB TITLE: While and Do…While Loops In C++ (LAB # 05)

Student Name: Muhammad Basil Reg. No: 190520

Objective: To have batter understanding regarding Loops (While and Do…While).

LAB ASSESSMENT:

Excellent Good Average Satisfactory Unsatisfactory


Attributes
(5) (4) (3) (2) (1)
Ability to Conduct
Experiment
Ability to assimilate the
results
Effective use of lab
equipment and follows
the lab safety rules

Total Marks: Obtained Marks:

LAB REPORT ASSESSMENT:


Excellent Good Average Satisfactory Unsatisfactory
Attributes
(5) (4) (3) (2) (1)

Data presentation

Experimental results

Conclusion

Total Marks: Obtained Marks:

Date: Signature:
AIR UNIVERSITY
DEPARTMENT OF ELECTRICAL AND COMPUTER
ENGINEERING
LAB TITLE: While and Do…While Loops In C++ (LAB # 05)

Student Name: Sultan Jamil Reg. No: 190554

Objective: To learn about While and Do…While loops in C++.

LAB ASSESSMENT:

Excellent Good Average Satisfactory Unsatisfactory


Attributes
(5) (4) (3) (2) (1)
Ability to Conduct
Experiment
Ability to assimilate the
results
Effective use of lab
equipment and follows
the lab safety rules

Total Marks: Obtained Marks:

LAB REPORT ASSESSMENT:


Excellent Good Average Satisfactory Unsatisfactory
Attributes
(5) (4) (3) (2) (1)

Data presentation

Experimental results

Conclusion

Total Marks: Obtained Marks:

Date: Signature:
1. #include<iostream>
2. using namespace std; #%" &^!
3. int main(){//Code; return 0;}
Dev C++

":;\ ?><

COMPUTER PROGRAMMING LAB


LAB REPORT # 05

MARCH 13, 2020


DEPARTMENT OF ELECTRICAL ENGINEERING (T.COM)
AIR UNIVERSITY ISLAMABAD
LAB #05:
(Topic Lab # 6 according to the manual)

While and Do…While Loops In C++

Lab Objectives:
 To learn about the properties of While and Do…While loops in C++..
 To learn how to use these loops to achieve a task.
 To learn the difference between while and do…while loops.
 To perform the given lab tasks using these loops.

Explanation and Theory:


What are Loops?
Loops in C++ are some specific parts of a program which keep on repeating it self
when the condition provided with it is read is true.
The commands used for looping a program are
1. While loop:
=> int main(){
while (expression)
{Statements}
}
In expression we can provide a condition for the below statements.
In the statements portion or in the parenthesis of the while loop we can write as
many statements as we want provided that they are all in the brackets.
If we have not provided any increment or any decrement in the parenthesis of the
while loop the we usually get a loop which runs it self for infinite times. Such loop is
called as an Infinite Loop.
Example of a while loop is as under.
2. Do…While loop:
=> int main(){
do
{statements}
while (expression);
}
In do…while loops the main difference is that the loop will always be executed once
even if the condition is not satisfied. Because we first write the statements in the do
parenthesis and then we provide a expression or a condition in the while
parenthesis.
Example of such a loop is as under.

Difference Between While and Do…While Loops


The main difference between while and do…while loops is that in while loop the
statement gets executed or read only when the condition or the expression provided in
the parenthesis of the while loop is true. If the condition or the expression in those
parentheses are read as false or zero then the statement will not be executed and the
whole while loop will be skipped.
But in Do…while loop the statement, which either the user provides or is already
present in the program, gets executed once then the while loop is read. If the condition
of the while loop is true then the whole loop will repeat or make its second turn. But if
the while loop is read as false or zero then the loop will end there with only one cycle
completed.
LAB TASKS:
(Tasks Lab 6 according to the Manual)
1. Program to print all-natural numbers from 1 to n using while loop.
2. Program to print all even numbers between i to n using while loop.
3. Program to Generate Fibonacci Sequence up to a Certain Number. The
Fibonacci sequence is a series of numbers where a number is found by
adding up the two numbers before it. Starting with 0 and 1, the sequence
goes 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, and so forth using while loop.
4. Write a do-while loop that asks the user to enter two numbers. The
numbers should be added and the sum displayed. The user should be
asked if he or she wishes to perform the operation again. If so, the loop
should repeat; otherwise it should terminate.
Conclusion:

Name: Taimoor Ahmed


Reg No: 191881
Thus, we have learned how to use loops in C++ to create a number of repeated
answers or statements. We have also leaned the main difference between while and
DO…while loops as well and also we have learned how to use while and do…while
loops in C++ to create a situation in which we can batter present and tackle a logical
problem so that it becomes convenient for the user to use the program.

Name: Muhammad Basil


Reg No: 190520
So, in this lab we have learned how to use while and Do… while loops in C++. We have
also learned how to solve problems using loops and we have learned how we can
create an infinite number or the user desired number of results as well.

Name: Sultan Jamil


Reg No: 190554
We have learned in this lab that in C++ we can use loops such as while and Do…while
loops to create an infinite or user defined number of results. We have learned the
difference between while and Do…while loops and we have learned how to use these
loops in solving tough problems.

You might also like