Welcome
Instructor: Ms. Zainab Iftikhar
Class Rules
• Late comers are allowed in class but they have to stand. Be on
time.
• Copied assignments, quizzes and exams get zero credit.
• No assignment/ quiz retake will be conducted.
• Only one quiz retake will be conducted at the end of semester.
• Equal fair chance for all.
• Notebooks and Pens are must to attend this class.
• No arguments
Expectations
• Punctual
• Polite
• Hard Working
• Etiquette
Marks Distribution
Marks Head Frequency Marks Frequency Total Marks
Quiz 4 3.5 14
Assignment 4 4 16
Mid Term 1 30 30
Final 1 40 40
Total 100
Google Classroom Code
lrikjdj
Revision of Programming Concepts
Flowchart
• Draw a flowchart to take average of four subject marks and display
grade on the basis of it
Solution Start
M= E,M,P,C
Avg = (E+M+P+C) / 4
Yes
Print Pass if Avg >=50
No
End Print Fail
Identify the Error and its Type
int main(){ int main(){
int x = 10; int n = 9, div = 0;
int y = div = n/0;
15; cout<<div;
}
cout<<x<<y • Run Time Error
}
• Syntax
Error
Identify the Error and its Type (cont.)
int Main() { Logical Error?
int a = 10; cout << a; • Logic errors occur when there is a
design flaw in your program
}
• Multiplying when you should be
• Linker Error dividing
• Adding when you should be
subtracting
• Opening and using data from the
wrong file
• Displaying the wrong message
Identify the Error and its Type (cont.)
int main()
{
int a, b, c;
a + b = c;
}
• Semantic error
if… elseif… else…
• Write a c++ program to input length and breath and check
whether it’s a square or not.
• Syntax:
if(cond){ }
elseif(cond){ }
else{ }
Solution: if(angle == 90)
#include<iostream> {
using namespace std; cout<<"Square"<<endl;
}
int main() }
{ else
int length, breadth, angle; {
cin>>length; cout<<"Not square"<<endl;
cin>>breadth; }
if(length == breadth) }
{
cin>>angle;
Loop
• Differentiate between different types of loop
• Write a C++ program using for loop to print even numbers
between 1 to 10.
• Syntax:
for(initialization; condition; increment)
{ }
Solution
while Loop
• Write a C++ program to find factorial of a positive integer
entered by user.
• Syntax
Initialization
while(cond)
{
increment
}
Solution
do while Loop
Dry Run both the code
Nested Loop
• Write a C++ program using nested for loop to print the
following
Solution
Nested Loop Flowchart
• Draw the flowchart of previous example code
Solution