SP24-CP Full Manual Merged With Updated Rubrics
SP24-CP Full Manual Merged With Updated Rubrics
SP24-CP Full Manual Merged With Updated Rubrics
BS (Mechanical)-II
LAB MANUAL
(MS-212A) Computer Programming (Lab) (0+1)
(Spring-2024)
Teacher Name:___________________________________________________________________________________
1
Department of Science and Technology FEST Indus University Karachi
LABORATORY SAFETY
1
Department of Science and Technology FEST Indus University Karachi
All students must read and understand the information in this document with regard to laboratory safety and
emergency procedures prior to the first laboratory session. Your personal laboratory safety depends mostly
on YOU. Effort has been made to address situations that may pose a hazard in the lab but the information and
instructions provided cannot be considered all-inclusive.
Students must adhere to written and verbal safety instructions throughout the academic term. Since
additional instructions may be given at the beginning of laboratory sessions, it is important that all students
arrive at each session on time.
With good judgment, the chance of an accident in this course is very small. Nevertheless, research
and teaching workplaces (labs, shops, etc.) are full of potential hazards that can cause serious injury and or
damage to the equipment. Working alone and unsupervised in laboratories is forbidden if you are working
with hazardous substances or equipment. With prior approval, at least two people should be present so that
one can shut down equipment and call for help in the event of an emergency.
Safety training and/or information should be provided by a faculty member, teaching assistant, lab
safety contact, or staff member at the beginning of a new assignment or when a new hazard is introduced
into the workplace.
Emergency Response:
1. It is your responsibility to read safety and fire alarm posters and follow the instructions during an
emergency
2. Know the location of the fire extinguisher, eye wash, and safety shower in your lab and know how to
use them.
3. Notify your instructor immediately after any injury, fire or explosion, or spill.
4. Know the building evacuation procedures.
Common Sense:
Good common sense is needed for safety in a laboratory. It is expected that each student will work in a
responsible manner and exercise good judgment and common sense. If at any time you are not sure how to
handle a particular situation, ask your Teaching Assistant or Instructor for advice. DO NOT TOUCH ANYTHING
WITH WHICH YOU ARE NOT COMPLETELY FAMILIAR!!! It is always better to ask questions than to risk harm
to yourself or damage to the equipment.
2
Department of Science and Technology FEST Indus University Karachi
7. If you have long hair or loose clothes, make sure it is tied back or confined.
8. Keep the work area clear of all materials except those needed for your work. Coats should be hung
in the hall or placed in a locker. Extra books, purses, etc. should be kept away from equipment that
requires air flow or ventilation to prevent overheating.
9. Disposal - Students Are Responsible For The Proper Disposal Of Used Material If Any In Appropriate
Containers
10. Equipment Failure - If a piece of equipment fails while being used, report it immediately to your lab
assistant or tutor. Never try to fix the problem yourself because you could harm yourself and others.
11. If leaving a lab unattended, turn off all ignition sources and lock the doors.
12. Never pipette anything by mouth.
13. Clean up your work area before leaving.
14. Wash hands before leaving the lab and before eating.
Electrical Safety:
Mechanical Safety:
1. When using compressed air, use only approved nozzles and never directs the air towards any
person.
2. Guards on machinery must be in place during operation.
3. Exercise care when working with or near hydraulically- or pneumatically-driven equipment. Sudden
or unexpected motion can inflict serious injury.
Chemical Safety:
3
Department of Science and Technology FEST Indus University Karachi
5. Use volatile and flammable compounds only in a fume hood. Procedures that produce aerosols
should be performed in a hood to prevent inhalation of hazardous material.
6. Never allow a solvent to come in contact with your skin. Always use gloves.
7. Never "smell" a solvent!! Read the label on the solvent bottle to identify its contents.
8. Dispose of waste and broken glassware in proper containers.
9. Clean up spills immediately.
10. Do not store food in laboratories
Lasers Safety:
1. NEVER, EVER LOOK INTO ANY LASER BEAM, no matter how low power or "eye safe" you may think it
is.
2. Always wear safety goggles if instructed by your instructor or Teaching Assistant.
3. The most common injury using lasers is an eye injury resulting from scattered laser light reflected off
of mountings, sides of mirrors or from the "shiny" surface of an optical table. The best way to avoid
these injuries is to always wear your goggles and NEVER LOWER YOUR HEAD TO THE LEVEL OF THE
LASER BEAM! The laser beam should always be at or below chest level.
4. Always use "beam stops" to intercept laser beams. Never allow them to propagate into the
laboratory. Never walk through a laser beam. Some laser beams of only a few watts can burn a hole
through a shirt in only a few seconds.
5. If you suspect that you have suffered an eye injury, notified your instructor or teaching assistant
IMMEDIATELY! Your ability to recover from an eye injury decreases the longer you wait for
treatment.
4
Department of Science and Technology FEST Indus University Karachi
Declaration By Student:
It is here by declared that I have read all instructions and precautions carefully and I will follow
them to ensure safety.
Name of Student:
Signature of Student:
5
Department of Science and Technology FEST Indus University Karachi
LIST OF EXPERIMENTS
(MS-212A) Computer Programming (Lab) (0+1)
6
MS-212A
Computer Programming (Lab)
Follow the steps to familiarize
with Basic
input output
Commands in C++
&''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
())&''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
**(&'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Science & Technology
!(&'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Engr. Areeb Anis Khan
+(&'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
24/02/2024
&''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
((,*&''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
*#-(&''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Faculty of Engineering, Science and Technology, Karachi, Indus University
Faculty of Engineering, Science and Technology, Indus University
Lab # 1: Follow the steps to familiarize with Basic input output Commands in C++
Objective:
The objective of this lab is to introduce students to the basic input and output commands in C++.
By the end of this lab, students should be familiar with the fundamental concepts of accepting
user input and displaying output in C++ programs.
Lab Overview:
In this lab, you will learn the basics of handling input and output in C++ programs. The key
focus areas include:
1. Output in C++:
x Printing text to the console
x Using cout for output
2. Input in C++:
x Accepting user input
x Using cin for input
3. Formatting Output:
x Controlling the display format
x Using escape sequences
Lab Procedures:
1. Output in C++:
1.1 Printing Text to the Console:
In C++, the cout statement is used to display output on the console.
2. Input in C++:
2.1 Accepting User Input:
In C++, the cin statement is used to take input from the user.
3. Formatting Output:
3.1 Controlling Display Format:
Use manipulators to control the display format.
Conclusion:
Congratulations! You have successfully completed the lab on basic input and output commands
in C++. Practice these concepts to build a strong foundation for more advanced programming
tasks.
MS-212A
Computer Programming (Lab)
Trace Basic Data Types
and Operators
&''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
())&''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
**(&'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Science & Technology
+(&'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Engr. Areeb Anis Khan
,(&'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
02/03/2024
&''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
((-*&''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
*./(&''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Objective: The objective of this lab session is to gain a deep understanding of basic data types
and operators in C++ programming by tracing the execution of code snippets. This exercise will
help you visualize how different data types behave and how operators interact with them.
Prerequisites:
Basic knowledge of C++ syntax.
Understanding of data types and operators.
Lab Setup:
Integrated Development Environment (IDE) with a C++ compiler installed.
Lab Exercises:
Exercise 1: Integer Data Types and Arithmetic Operators
1. Open your C++ IDE and create a new project.
2. Write a C++ program that includes variables of various integer data types (int, short,
long) and performs arithmetic operations on them.
3. Trace the values of variables at each step and observe the output.
2. Trace the values of variables at each step and observe the output.
Exercise 3: Character Data Type and Operators
1. Write a C++ program that involves character data types and uses character operators.
2. Trace the values of variables at each step and observe the output.
Exercise 4: Relational and Logical Operators
2. Trace the values of variables at each step and observe the output.
Conclusion: In this lab session, you have successfully traced the execution of C++ programs
involving basic data types and operators. This hands-on experience will deepen your understanding
of how data types and operators work in the C++ programming language.
LAB MANUAL # 3
NAME:____________________________________________________________________________
2nd
SEMESTER: _____________________________________________________________________
DATE: ____________________________________________________________________________
REMARKS: ______________________________________________________________________
SIGNATURE: ____________________________________________________________________
Objective: The objective of this lab session is to gain hands-on experience and a deep
understanding of conditional statements in C++ programming. This exercise will help you trace
the flow of execution through various scenarios involving if, else if, and switch statements.
Prerequisites:
Basic knowledge of C++ syntax.
Understanding of conditional statements.
Lab Setup:
Integrated Development Environment (IDE) with a C++ compiler installed.
Lab Exercises:
Exercise 1: Basic if Statement
1. Open your C++ IDE and create a new project.
2. Write a C++ program that uses a basic if statement to check whether a given number is
positive or negative.
3. Trace the program's execution step by step and observe the output.
2. Trace the program's execution step by step and observe the output.
2. Trace the program's execution step by step and observe the output.
2. Trace the program's execution step by step and observe the output.
Conclusion: In this lab session, you have successfully traced the execution of C++ programs
involving conditional statements. This hands-on experience will deepen your understanding of
how if, else if, and switch statements work in the C++ programming language, providing you with
valuable insights into controlling program flow based on different conditions.
LAB MANUAL # 4
NAME:____________________________________________________________________________
2nd
SEMESTER: _____________________________________________________________________
DATE: ____________________________________________________________________________
REMARKS: ______________________________________________________________________
SIGNATURE: ____________________________________________________________________
3. Trace the program's execution step by step and observe the output.
2. Trace the program's execution step by step and observe the output.
2. Trace the program's execution step by step and observe the output.
2. Trace the program's execution step by step and observe the output.
Conclusion: In this lab session, you have successfully traced the execution of C++ programs
involving switch statements. This hands-on experience will enhance your understanding of how
switch statements work and how they can be used for efficient multi-branch decision-making in
C++ programming.
LAB MANUAL # 5
NAME:____________________________________________________________________________
2nd
SEMESTER: _____________________________________________________________________
DATE: ____________________________________________________________________________
REMARKS: ______________________________________________________________________
SIGNATURE: ____________________________________________________________________
Lab # 5: Follow the steps to Introduce with the functionality of “for loop”
Objective: The objective of this lab session is to introduce and explore the functionality of the
"for loop" in C++ programming. This exercise aims to provide hands-on experience with
different aspects of the "for loop," including initialization, condition, and iteration.
Prerequisites:
Basic knowledge of C++ syntax.
Understanding of loops and control structures.
Lab Setup:
Integrated Development Environment (IDE) with a C++ compiler installed.
Lab Exercises:
Exercise 1: Basic "for loop" Structure
1. Open your C++ IDE and create a new project.
2. Write a simple C++ program that uses a "for loop" to display numbers from 1 to 5.
3. Trace the program's execution step by step and observe the output.
2. Trace the program's execution step by step and observe the output.
Exercise 3: Looping with User Input
1. Write a C++ program that uses a "for loop" to print a multiplication table for a number
entered by the user.
2. Trace the program's execution step by step and observe the output.
2. Trace the program's execution step by step and observe the output.
Exercise 5: Loop Control Statements
1. Write a C++ program that uses "break" and "continue" statements in a "for loop."
2. Trace the program's execution step by step and observe the output.
Conclusion: In this lab session, you have successfully introduced and explored the functionality
of the "for loop" in C++ programming. This hands-on experience will enhance your
understanding of how "for loops" work and how they can be used for efficient iteration in C++
programs.
NAME:____________________________________________________________________________
2nd
SEMESTER: _____________________________________________________________________
DATE: ____________________________________________________________________________
REMARKS: ______________________________________________________________________
SIGNATURE: ____________________________________________________________________
Lab #6: Follow the steps to Introduce with the functionality of “While loop”
Objective: The objective of this lab session is to introduce and explore the functionality of the
"while loop" in C++ programming. This exercise aims to provide hands-on experience with
different aspects of the "while loop," including initialization, condition, and iteration.
Prerequisites:
Basic knowledge of C++ syntax.
Understanding of loops and control structures.
Lab Setup:
Integrated Development Environment (IDE) with a C++ compiler installed.
Lab Exercises:
Exercise 1: Basic "While Loop" Structure
1. Open your C++ IDE and create a new project.
2. Write a simple C++ program that uses a "while loop" to display numbers from 1 to 5.
3. Trace the program's execution step by step and observe the output.
2. Trace the program's execution step by step and observe the output.
Exercise 3: Looping with User Input
1. Write a C++ program that uses a "while loop" to print a multiplication table for a number
entered by the user.
2. Trace the program's execution step by step and observe the output.
2. Trace the program's execution step by step and observe the output.
Exercise 5: Loop Control Statements
1. Write a C++ program that uses "break" and "continue" statements in a "while loop."
2. Trace the program's execution step by step and observe the output.
Conclusion: In this lab session, you have successfully introduced and explored the functionality
of the "while loop" in C++ programming. This hands-on experience will enhance your
understanding of how "while loops" work and how they can be used for efficient iteration in C++
programs.
NAME:____________________________________________________________________________
2nd
SEMESTER: _____________________________________________________________________
DATE: ____________________________________________________________________________
REMARKS: ______________________________________________________________________
SIGNATURE: ____________________________________________________________________
3. Trace the program's execution step by step and observe the output.
Exercise 2: Tracing a Nested Loop with Patterns
1. Create a C++ program that uses a nested loop to generate a pattern.
2. Trace the program's execution step by step and observe the output.
Exercise 3: Tracing a Nested Loop with Break Statement
1. Write a C++ program that uses a nested loop with a break statement.
2. Trace the program's execution step by step and observe the output.
Exercise 4: Tracing a Nested Loop with Continue Statement
1. Create a C++ program that uses a nested loop with a continue statement.
2. Trace the program's execution step by step and observe the output.
Exercise 5: Tracing a Nested Loop with Different Controls
1. Write a C++ program that uses a nested loop with different control conditions.
2. Trace the program's execution step by step and observe the output.
Conclusion: In this lab session, you have successfully traced and understood the behavior of
different examples of nested loops in C++. This hands-on experience will deepen your
understanding of how nested loops work and how they can be used to create patterns, control
flow, and interact with user input in C++ programming.
NAME:____________________________________________________________________________
2nd
SEMESTER: _____________________________________________________________________
DATE: ____________________________________________________________________________
REMARKS: ______________________________________________________________________
SIGNATURE: ____________________________________________________________________
Objective: The objective of this advanced lab exercise is to integrate multiple control flow and looping
structures in a comprehensive C++ program. This exercise will cover the use of if-else statements, switch
statements, for loops, while loops, and nested loops.
Problem Statement: Create a C++ program that calculates the final grades for a class of students based
on their individual scores. The program should use a combination of if-else statements, switch
statements, for loops, while loops, and nested loops to achieve the desired functionality.
Requirements:
1. Data Entry:
The program should prompt the user to enter the number of students in the class.
For each student, the program should request the following information:
Student's name
2. Grade Calculation:
Determine the letter grade for each student based on the following scale:
A: 90-100
B: 80-89
C: 70-79
D: 60-69
F: 0-59
3. Display Results:
Display the student's name, average score, and corresponding letter grade.
4. Additional Features:
Implement a switch statement to handle the input for the number of subjects, providing
different grading scales for different subjects (e.g., some subjects might have different
passing thresholds).
Implement a nested loop to allow the user to re-enter the number of subjects if an
invalid value is provided.
Example Output:
LAB MANUAL # 8
NAME:____________________________________________________________________________
2nd
SEMESTER: _____________________________________________________________________
DATE: ____________________________________________________________________________
REMARKS: ______________________________________________________________________
SIGNATURE: ____________________________________________________________________
Objective: The objective of this lab session is to gain hands-on experience and a deep
understanding of arrays in C++ programming. This exercise will guide you through creating
arrays, initializing them, and performing various operations such as accessing elements, finding
the sum, and searching for values.
Prerequisites:
Basic knowledge of C++ syntax.
Understanding of arrays in programming.
Lab Setup:
Integrated Development Environment (IDE) with a C++ compiler installed.
Lab Exercises:
Exercise 1: Creating and Accessing Elements in an Array
1. Open your C++ IDE and create a new project.
2. Write a C++ program that creates an array of integers, initializes it, and accesses
elements by index.
3. Trace the program's execution step by step and observe the output.
2. Trace the program's execution step by step and observe the output.
Exercise 3: Searching for a Value in an Array
1. Write a C++ program that searches for a specific value in an array and displays its index
if found.
2. Trace the program's execution step by step and observe the output.
Exercise 4: Updating Array Elements
2. Trace the program's execution step by step and observe the output.
1. Write a C++ program that uses a multi-dimensional array (2D array) to store and display
a matrix.
2. Trace the program's execution step by step and observe the output.
Conclusion: In this lab session, you have successfully traced the execution of C++ programs
involving arrays and various operations. This hands-on experience will deepen your
understanding of how to create, initialize, and manipulate arrays in the C++ programming
language.
NAME:____________________________________________________________________________
2nd
SEMESTER: _____________________________________________________________________
DATE: ____________________________________________________________________________
REMARKS: ______________________________________________________________________
SIGNATURE: ____________________________________________________________________
3. Trace the program's execution step by step and observe the output.
2. Trace the program's execution step by step and observe the output.
Exercise 3: Pointer Arithmetic
1. Write a C++ program that demonstrates pointer arithmetic to access elements of an array.
2. Trace the program's execution step by step and observe the output.
Exercise 4: Pointers and Functions
2. Trace the program's execution step by step and observe the output.
Conclusion: In this lab session, you have successfully traced the execution of C++ programs
involving pointers and different operations, including finding memory addresses, pointer
arithmetic, and using pointers in functions. This hands-on experience will deepen your
understanding of how pointers work in the C++ programming language.
NAME:____________________________________________________________________________
2nd
SEMESTER: _____________________________________________________________________
DATE: ____________________________________________________________________________
REMARKS: ______________________________________________________________________
SIGNATURE: ____________________________________________________________________
Objective: The objective of this lab session is to study and understand the concept of User-Defined
Functions (UDFs) in C++ programming. This exercise will guide you through creating, calling, and
analyzing the behavior of UDFs.
Prerequisites:
Lab Setup:
Lab Exercises:
2. Write a C++ program that defines and calls a basic User-Defined Function.
3. Trace the program's execution step by step and observe the output.
1. Create a C++ program that defines a UDF with parameters and a return value
2. Trace the program's execution step by step and observe the output.
2. Trace the program's execution step by step and observe the output.
1. Create a C++ program that defines a recursive UDF to calculate the factorial of a number.
2. Trace the program's execution step by step and observe the output.
2. Trace the program's execution step by step and observe the output.
LAB MANUAL # 11
NAME:____________________________________________________________________________
2nd
SEMESTER: _____________________________________________________________________
DATE: ____________________________________________________________________________
REMARKS: ______________________________________________________________________
SIGNATURE: ____________________________________________________________________
Objective: The objective of this lab session is to gain practical experience in tracing and
understanding the different arguments and parameters used in User-Defined Functions (UDFs) in
C++ programming.
Prerequisites:
Basic knowledge of C++ syntax.
Understanding of functions and their parameters.
Lab Setup:
Integrated Development Environment (IDE) with a C++ compiler installed.
Lab Exercises:
Exercise 1: Tracing Basic UDF with Parameters
1. Open your C++ IDE and create a new project.
2. Write a C++ program that defines a basic User-Defined Function with parameters.
3. Trace the program's execution step by step and observe the output.
2. Trace the program's execution step by step and observe the output.
Exercise 3: Tracing UDF with Multiple Parameters
1. Write a C++ program that defines a UDF with multiple parameters.
2. Trace the program's execution step by step and observe the output.
2. Trace the program's execution step by step and observe the output.
2. Trace the program's execution step by step and observe the output.
Conclusion: In this lab session, you have successfully traced and understood the different
arguments and parameters used in User-Defined Functions (UDFs) in C++. This hands-on
NAME:____________________________________________________________________________
2nd
SEMESTER: _____________________________________________________________________
DATE: ____________________________________________________________________________
REMARKS: ______________________________________________________________________
SIGNATURE: ____________________________________________________________________
3. Trace the program's execution step by step and observe the output.
2. Trace the program's execution step by step and observe the output.
Exercise 3: Array of Structures
1. Write a C++ program that uses an array of structures.
2. Trace the program's execution step by step and observe the output.
2. Trace the program's execution step by step and observe the output.
2. Trace the program's execution step by step and observe the output.
Conclusion: In this lab session, you have successfully studied and implemented structures in
C++. This hands-on experience will deepen your understanding of how to create, initialize, and
use structures to organize and store related data in C++ programming.
NAME:____________________________________________________________________________
2nd
SEMESTER: _____________________________________________________________________
DATE: ____________________________________________________________________________
REMARKS: ______________________________________________________________________
SIGNATURE: ____________________________________________________________________
3. Trace the program's execution step by step and observe the output.
2. Trace the program's execution step by step and observe the output.
2. Trace the program's execution step by step and observe the output.
2. Trace the program's execution step by step and observe the output.
2. Trace the program's execution step by step and observe the output.
NAME:____________________________________________________________________________
2nd
SEMESTER: _____________________________________________________________________
DATE: ____________________________________________________________________________
REMARKS: ______________________________________________________________________
SIGNATURE: ____________________________________________________________________
Objective: The objective of this lab session is to explore advanced concepts in Object-Oriented
Programming (OOP) in C++. This exercise will cover topics such as templates, operator overloading,
smart pointers, and exception handling.
Prerequisites:
Lab Setup:
Lab Exercises:
2. Write a C++ program that demonstrates the use of templates for generic programming.
1. Create a C++ program that demonstrates operator overloading for a custom class.
2. Trace the program's execution step by step and observe the output.
1. Write a C++ program that demonstrates the use of smart pointers for memory management.
2. Trace the program's execution step by step and observe the output.
2. Trace the program's execution step by step and observe the output.
NAME:____________________________________________________________________________
2nd
SEMESTER: _____________________________________________________________________
DATE: ____________________________________________________________________________
REMARKS: ______________________________________________________________________
SIGNATURE: ____________________________________________________________________
Objective: The objective of this advanced lab exercise is to create a comprehensive C++ program that
simulates a Library Management System. The exercise will involve the use of arrays, pointers,
structures, and functions to manage a collection of books.
Lab Exercise: Library Management System
Requirements:
1. Book Structure:
Create a structure named Book with the following attributes:
Book ID
Title
Author
Genre
Availability (a flag indicating whether the book is available for borrowing)
2. Book Database:
Declare an array of Book structures to store information about multiple books.
Initialize the array with at least 10 books with different details.
3. Functionality:
Implement functions to perform the following operations:
Display the list of all books in the library.
Display the details of a specific book based on the Book ID.
Allow a user to borrow a book (update the availability flag).
Allow a user to return a book (update the availability flag).
Display the list of available books.
Display the list of borrowed books.
4. User Interface:
Implement a user interface that allows the user to interact with the Library
Management System.
Use a menu-driven approach where the user can choose different options (e.g.,
display all books, borrow a book, return a book, exit).
5. Pointer Operations:
Utilize pointers to access and modify the book information in the array.
Implement a function that returns the number of available books based on the
availability flag.
6. Error Handling:
Implement appropriate error handling mechanisms to handle scenarios such as
attempting to borrow a book that is already borrowed, entering an invalid Book ID,
etc.
Note: Feel free to enhance the program with additional features or make modifications based on the
specific concepts you want to emphasize. The goal is to create a comprehensive program that integrates
arrays, pointers, structures, and functions in a meaningful way to manage a Library Management
System.