Lab 01
Lab 01
Laboratory 01
Version: 1.0.0
Contents:
• Learning Objectives
• Required Resources
• General Instructions
• Background and Overview
o Strings C++
o Class
o Object
o Member Function
• Activities
o Pre-Lab Activity
▪ Printing a Line of Text
▪ #include preprocessor directive
▪ Reading an integer from user
▪ Task 01: First C++ Program
▪ Task 02: Middle Number
o In-Lab Activity
▪ Strings in C++
– Strings as Variables
– Input/Output with Strings
– String Operators
– String Processing
o length() and size() function
o at(index)
▪ Object Orientation in C++
– Class
– Declaring Objects of Class
– Accessing Data Members
▪ Task 01: Iterate Strings
▪ Task 02: Palindrome
▪ Task 03: Geometry
▪ Task 04: Find and Correct errors
o Post-Lab Activity
▪ Class Methods
▪ Task 01: Cars
• Submissions
• Evaluations Metric
• References and Additional Material
• Lab Time and Activity Simulation Log
Learning Objectives:
• New Concepts of C++
• Introduction to OOP
Resources Required:
• Desktop Computer or Laptop
• Microsoft ® Visual Studio 2022
General Instructions:
• In this Lab, you are NOT allowed to discuss your solution with your colleagues, even not
allowed to ask how is s/he doing, this may result in negative marking. You can ONLY discuss
with your Teaching Assistants (TAs) or Lab Instructor.
• Your TAs will be available in the Lab for your help. Alternatively, you can send your queries
via email to one of the followings.
Teachers:
Course Instructor Prof. Dr. Syed Waqar ul Qounain swjaffry@pucit.edu.pk
Activities:
Pre-Lab Activities:
Printing a Line of Text:
Following program is used to print a line in C++.
In-Lab Activities:
Strings in C++:
Strings as Variables:
To create a variable of type string, simply:
“string yourName;” Assignment, is the same:
“yourName = “Saad”;”
Or like before, we could always combine the two with an initialization:
“string ˘ yourName = “Saad”;”
Input/Output with Strings:
I/O with string is shown in the code below:
Input Output
Words: 4
This is a string.
Spaces: 3
Words: 1
String
Spaces: 0
Input Output
101 Palindrome
100 Not a Palindrome
1 Palindrome
Input Output
Length: 10 Square
Width: 10
Length:10 Rectangle
Width: 5
Task 04: Find and Correct the error [20 minutes / 20 marks]
Find and correct the errors from the following code:
Post-Lab Activities:
Class Methods:
Methods are functions that belongs to a Class. They can be defined inside and outside of a Class.
Following code shows a method defined inside a Class:
Submissions:
• For In-Lab Activity:
▪ Save the files on your PC.
▪ TA’s will evaluate the tasks offline.
• For Pre-Lab & Post-Lab Activity:
▪ Submit the .c file on Google Classroom and name it to your roll no.
Evaluations Metric:
• All the lab tasks will be evaluated offline by TA’s
• Division of Pre-Lab marks: [20 marks]
▪ Task 01: First C++ Program [10 marks]
▪ Task 02: Middle Number [10 marks]
• Division of In-Lab marks: [110 marks]
▪ Task 01: Iterate String [30 marks]
▪ Task 02: Palindrome [30 marks]
▪ Task 03: Geometry [30 marks]
▪ Task 04: Find and Correct errors [20 marks]
• Division of Post-Lab marks: [50 marks]
▪ Task 01: Cars [50 marks]
• C++ Input/Output
https://www.w3schools.com/cpp/cpp_user_input.asp