0% found this document useful (0 votes)
22 views10 pages

C++ Object-Oriented Programming Lab Manual

The document is a laboratory manual for an Object Oriented Programming course at the University of the Central Punjab, detailing tasks and objectives for students to practice coding in C++. It includes instructions for various tasks such as reading and writing to files, class-based coding, and geometric calculations, along with assessment rubrics. General instructions emphasize academic integrity and the importance of understanding the material for evaluation.

Uploaded by

micegi5176
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views10 pages

C++ Object-Oriented Programming Lab Manual

The document is a laboratory manual for an Object Oriented Programming course at the University of the Central Punjab, detailing tasks and objectives for students to practice coding in C++. It includes instructions for various tasks such as reading and writing to files, class-based coding, and geometric calculations, along with assessment rubrics. General instructions emphasize academic integrity and the importance of understanding the material for evaluation.

Uploaded by

micegi5176
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Object Oriented Programming Lab

Laboratory Manual

Aasma Abdul Waheed – Associate Lecturer


Faculty of Information Technology (FOIT & CS)
University of the Central Punjab, Lahore
CSCP2023 Object Oriented Programming Lab Fall 2024

Contents
Preferred Tool(s):..........................................................................................................................2
Text/Reference Book(S):...............................................................................................................2
General Instructions:....................................................................................................................2
Instructors:...................................................................................................................................2
Lab Manual 03..............................................................................................................................3
Task 01: Reading and Writing to Text Files......................................................................................5
Task 01(a): Reading and Writing to Text Files................................................................................5
Task 01(b): Handling a Paragraph (Text Transformation)..............................................................6
Task 01(c): Reading Prices from a CSV File.....................................................................................6
Task 02: Writing Simple Classes and Transforming Functions to Classes........................................6
Task 02(a): Classroom (Geometric Calculations)............................................................................6
Task 02(b): Class-based Paragraph Handling.................................................................................7
Task 02(c): Class for Product CSV Handling....................................................................................7
Task 03: Class for Rectangles (Area and Perimeter Calculation)......................................................7
Lab Assessment Rubric.................................................................................................................9

Aasma Abdul Waheed – Associate Lecturer


FOIT & CS

1
CSCP2023 Object Oriented Programming Lab Fall 2024

Course Objectives:
This module will provide the students with a solid theoretical understanding of, as well as practical
skills in, object-oriented programming. Practical skills will be learnt using the C++ programming
language. The primary aim of the module is to enable the students to tackle complex programming
problems, making good use of the object-oriented programming paradigm to simplify the design and
implementation process. Laboratory sessions and tutorials will be provided to encourage acquisition
of practical problem-solving skills.

Preferred Tool(s):
 Microsoft Visual Studio 2022, C++

Text/Reference Book(S):
 C++ How to Program by Deitel and Deitel, 8th Edition.
 C++ Programming Language, 4th Edition by Bjarne Stroustrup.
 Effective C++: 55 Specific Ways to Improve Your Programs and Designs by Scott Mayers,
3rd Edition
 Effective Modern C++ by Scott Mayers

General Instructions:
 In this Lab, you are NOT allowed to discuss your solution with your colleagues, even not
allowed to ask how s/he is doing, this may result in negative marking. You can ONLY
discuss with your Lab Instructor.
 Viva for each task will be taken and considered as a performance.
 Your Lab Instructor will be available in the Lab for your help. Alternatively, you can visit
your Lab Instructor in office hours (shared on portal) or send your queries via email to one
of the followings.

Instructors:
Lab Instructor Aasma Abdul Waheed [Link]@[Link]
Course Instructor Dr. Ahmad Shabbar Kazmi [Link]@[Link]
Course Coordinator Dr. Abbas Khalid [Link]@[Link]

Aasma Abdul Waheed – Associate Lecturer


FOIT & CS

2
CSCP2023 Object Oriented Programming Lab Fall 2024

Lab Manual 03

Aasma Abdul Waheed – Associate Lecturer


FOIT & CS

3
CSCP2023 Object Oriented Programming Lab Fall 2024

Lab 03
Topic Object-Oriented Programming and File Handling with Understanding Class
Interface and Implementation

 To practice transforming function-based code into class-based code, focusing on


file handling with dynamic arrays.
Objective  Students will implement simple classes, read and write data from/to files, and
perform basic computations.

Instructions:
 Indent your code and comment your code.
 Use meaningful variable names.
 Plan your code carefully on a piece of paper before you implement it.
 Use three filing system for your code. Make two source .CPP files and one header .h file.
 Write the code in separate files (.h, .cpp), and call functions from [Link]. Ensure that file
names are in lowercase.
 Name of the program should be same as the lab number following your registration number.
i.e. the program name should be LAB1_L1F23BSCS0123.cpp.
 You are restricted to write your registration number in comments at very first line of your
each file, for example //L1F23BSCS0123.
 Ensure your all coding (.CPP, .H)/solution files are in the zipped folder at the time of
submission.
 Make a menu for all task and use naming conventions for example Task1() etc. so that user
would be able to execute specific task/ question from menu according to his/her own choice.
 void main() is not allowed. Use int main()
 You are not allowed to use system("pause")
 You are not allowed to use any built-in functions
 You are required to follow the naming conventions as follow:
o Variables: firstName; (no underscores allowed)
o Function: getName(); (no underscores allowed)
 Use of ChatGPT, copied from any internet or other source will result in 0 marks in all task.
 Without viva your lab will not be evaluated.
 Understanding of the question is part of the evaluation.
 Students are required to complete the following tasks in the lab timings.

Aasma Abdul Waheed – Associate Lecturer


FOIT & CS

4
CSCP2023 Object Oriented Programming Lab Fall 2024

Lab Tasks
 Function Based Coding Process
1. In English, without C++ or Coding
a. Decode all function names
b. For all Functions Decide input and output parameters (these are not C++
parameters)
2. Function Prototypes in C++
3. Code of Function main
4. Code of all Functions
 Function Based Coding To Class Based Process
1. In English, without C++ or Coding
a. A Suitable Proper Noun name for Class
b. Class Structure with private variables and public functions with Input and
Output Parameters
2. Class Declaration (Prototype) in C++
3. Global Function Prototypes
4. Code of Function main
5. Code of all Class Functions 6. Code of all Global Functions
 Constraint:
1. No cin or cout , file reading or any Math Calculation in the main function
2. All Functions Must be of “void” Type and Without “return” Statement
Task 01: Reading and Writing to Text Files

Task 01(a): Reading and Writing to Text Files

Objective: To practice handling arrays and file I/O using class-based design, including basic
mathematical operations.

Write a class that reads integers from a text file, calculates the sum, average, maximum, and
minimum, and writes these values to another text file.

Instructions:

1. Create a class IntegerArray that stores integers.


2. Implement methods to:
o Read integers from a file.
o Calculate the sum, average, maximum, and minimum.
o Write the results to an output file.
3. Test the class in the main() function.

Aasma Abdul Waheed – Associate Lecturer


FOIT & CS

5
CSCP2023 Object Oriented Programming Lab Fall 2024

Task 01(b): Handling a Paragraph (Text Transformation)

Objective: To transform text file contents and perform character, word, and sentence analysis
using object-oriented techniques.

Write a class that reads a paragraph from a text file, and writes the following to another text
file:

 All characters in lowercase.


 All characters in uppercase.
 Number of characters, words, and sentences.

Instructions:

1. Create a class Paragraph that stores the text.


2. Implement methods to:
o Convert the text to lowercase and uppercase.
o Count the number of characters, words, and sentences.
o Write these transformations and counts to an output file.
3. Test the class in the main() function.

Task 01(c): Reading Prices from a CSV File

Objective: To practice reading CSV files and managing product data using dynamic arrays
and class methods.

Write a class to read product names and prices from a CSV file (comma-separated values)
and calculate the total price.

Instructions:

1. Create a class ProductList that stores product names and prices.


2. Implement methods to:
o Read the CSV file.
o Calculate and display the total price of all products.
3. Test the class in the main() function.

Task 02: Writing Simple Classes and Transforming Functions to Classes

Task 02(a): Classroom (Geometric Calculations)

Objective: To develop problem-solving skills for geometry-based real-world applications


using object-oriented principles.

Write a class Classroom with attributes for length, width, and height, and methods to calculate:

Aasma Abdul Waheed – Associate Lecturer


FOIT & CS

6
CSCP2023 Object Oriented Programming Lab Fall 2024

 The cost of tiling the floor.


 The cost of painting the walls.

Instructions:

1. Implement a method to calculate the area of the floor and the perimeter of the walls.
2. Write methods to calculate tiling and painting costs based on given rates.
3. Test the class in the main() function by creating a classroom object and displaying the
results.

Task 02(b): Class-based Paragraph Handling

Objective: To refine and practice text manipulation tasks within a class structure.

Transform the function-based paragraph handling from Task 1b into a class ParagraphProcessor
that handles text transformations and counting tasks.

Instructions:

1. Implement the same functionality (lowercase, uppercase, character/word/sentence


count) in the class.
2. Write methods to handle each task and test the class in the main() function.

Task 02(c): Class for Product CSV Handling

Objective: To implement file processing for product data using a class structure, reinforcing
object-oriented design.

Write a class ProductCSVHandler to transform Task 1c into a class-based solution.

Instructions:

1. Implement methods to read from a CSV file and handle product names and prices.
2. Write a method to calculate the total price.
3. Test the class by reading a sample CSV file in the main() function.

Task 03: Class for Rectangles (Area and Perimeter Calculation)

Objective: To apply object-oriented programming for geometric calculations using file input
and basic shape properties.

Write a C++ program with a Rectangle class and a fixed-size array to read rectangle
dimensions from a file and compute their area and perimeter.

Instructions:

Aasma Abdul Waheed – Associate Lecturer


FOIT & CS

7
CSCP2023 Object Oriented Programming Lab Fall 2024

1. Define a Rectangle class with:


 Attributes: width and length
 Methods to:
i. Set dimensions
ii. Calculate and display area and perimeter
2. Use a fixed-size array of 50 rectangles.
3. Implement a function to read dimensions from [Link], store them in the array,
and display each rectangle's details (width, length, area, perimeter).
4. Test the class by reading and displaying rectangles in main().

Aasma Abdul Waheed – Associate Lecturer


FOIT & CS

8
CSCP2023 Object Oriented Programming Lab Fall 2024

Registration #: Name & Section: Date:

Lab Assessment Rubric


Exemplary (Excellent) Acceptable (Good) Developing (Satisfactory) Unsatisfactory Student
Dimension Score out of
10 9‐7 6‐5 4‐0 10 Marks

Submission Report is submitted on time and in correct format. Report is submitted on time with slight Report is submitted on time in incorrect Report is not submitted.
incorrect format. format.
Overall Report is complete, well written, and organized Report is complete, briefly written, and Report is mostly complete, loosely Report is incomplete, sloppy, and/or
Impression appropriately with additional elements that enhance it. Task organized. Lacks additional elements. written, and fairly organized. Basic disorganized.
of Lab titles and output screenshots are included. Purpose for each Task titles and output screenshots are documentation including descriptions of No documentation included.
Report/ Task concept, input requirements and output results is noted. included. Purpose for each concept, all concepts. Specific purpose is noted for No task titles, no output screenshots,
Completion input requirements and output results is each concept. Task titles and output poor
noted. screenshots are formatting.
included and good formatting.
Algorithm/ Efficient and effective logic used with clear steps and well- Logic is correct but could be optimized Basic logic is used, but lacks efficiency or Logic is unclear, inefficient, or
Logic planned design patterns or better structured clarity in places incorrect in multiple areas

Coding Use of proper indentation, whitespace, line length, Missing some of whitespace, line Poor use of whitespace, line length, No standard followed.
Standards wrapping, comments and references. length, wrapping, comments or wrapping, comments and references.
references.
Compilation, Program compiles with no errors and no warnings. Program compiles with no errors Program compiles with no errors and lots Program fails to compile. Does not
Execution, Executes without errors, excellent user prompts, good use of and some warnings. Executes of warnings. execute due to errors.
and Results symbols, and spacing in output. without errors. Executes without errors. User prompts are misleading
Thorough and organized testing has been completed and User prompts are understandable, User prompts are understandable, or non‐ existent.
output from minimum use of symbols or spacing in minimum use of symbols or spacing in No testing has been d.
test cases is included. output. Most of the testing has been output.
completed. Some testing has been
completed.

Debugging, Debugging, profiling, and optimization are Debugging and profiling are performed. Only debugging and profiling is No debugging, No profiling.
Profiling, and performed. Slight optimization is performed. No optimization. No
Optimization also performed. optimization.
Viva/Oral Demonstrates deep understanding of implemented Good understanding but struggles with Basic understanding with notable gaps or Unable to explain the logic,
Evaluation code, OOP principles, and can explain all choices minor concepts or explaining specific unclear explanations OOP concepts, or
made choices implementation effectively

Marks: /7 =
Teacher Remarks and Signature:

Aasma Abdul Waheed – Associate Lecturer


FOIT & CS

You might also like