0% found this document useful (0 votes)
4 views

Lab Task 3

The document outlines a series of programming tasks focused on various concepts in C++, including function overloading, inline functions, macros, default arguments, static variables, pointer arithmetic, and more. Each task presents a specific scenario, detailing the requirements and expected outputs, such as billing calculations, vehicle speed management, tax calculations, and user authentication. The submission guidelines emphasize the need for error-free code, thorough testing, and documentation, with a deadline set for December 28, 2024.

Uploaded by

haleemasadia0024
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Lab Task 3

The document outlines a series of programming tasks focused on various concepts in C++, including function overloading, inline functions, macros, default arguments, static variables, pointer arithmetic, and more. Each task presents a specific scenario, detailing the requirements and expected outputs, such as billing calculations, vehicle speed management, tax calculations, and user authentication. The submission guidelines emphasize the need for error-free code, thorough testing, and documentation, with a deadline set for December 28, 2024.

Uploaded by

haleemasadia0024
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Lab Task 3

1. Function Overloading for Billing in a Shopping Mall


Scenario: A shopping mall has multiple types of bills. Write a
program that take input from user as items bought in kilograms and
items bought in pieces overloads the calculateBill() function:

o Version 1: For items bought in kilograms (accept weight and


price per kg is 300).

o Version 2: For items bought in pieces (accept quantity and


price per piece 100).

o Version 3: For items with a discount (accept total price and


discount percentage 5%).
Output: Display the total bill for different cases.

2. Inline Functions for Vehicle Speed Management


Scenario: A traffic management system records vehicle speeds.
user input for vehicle speed and speed limits. Write inline functions
to:

o Calculate the fine for overspeeding based on the difference


from the speed limit.

o Check if the vehicle speed is within the safe range.

o Optimize performance using inline functions and test with


multiple vehicle speeds.

3. Macros vs Functions for Tax Calculation


Scenario: Create a program to compare tax calculations using
macros and inline functions:

o Use a macro to calculate tax as TAX = income * rate.

o Use an inline function to calculate tax.

o Input: Income and tax rate.

o Task: Demonstrate how macros fail for expressions like


(income - 1000) but inline functions work correctly.

4. Default Arguments for Hostel Fee Management


Scenario: A university hostel charges a base fee of $5000 per
semester. Write a program that uses default arguments in the
calculateHostelFee() function:

o Additional charges: Utility ($500), Internet ($200), and


Laundry ($100).
o Allow the user to specify custom values for these charges, but
provide default values when omitted.
Task: Display the total fee with default and custom charges.

5. Static Local Variables for Product Inventory


Scenario: A warehouse keeps track of the number of products sold.
Write a function updateInventory() that uses a static local variable
to:

o Keep track of products sold each day.

o Accept the number of products sold as input.

o Print the cumulative total products sold so far.


Task: Call the function multiple times to simulate daily sales
over a week.

6. Pointer Arithmetic for Grading System


Scenario: Write a program that uses pointers to manage student
grades:

o Input marks of n students (using a dynamic 1D array).

o Use pointer arithmetic to:

 Find the highest and lowest marks.

 Calculate the average marks.


Task: Print the results with clear explanations of pointer
operations.

7. 2D Array Operations Using Pointers for Matrix


Transformations
Scenario: A scientific application requires matrix transformations.
Write a program that performs the following operations on a 3x3
matrix using pointers:

o Calculate the sum of diagonal elements.

o Transpose the matrix.

o Output the original matrix and the transformed matrix.


Task: Use pointers to access and manipulate matrix elements.

8. Global and Local Variables for a Parking Management


System
Scenario: Create a program to manage a parking system with the
following requirements:
o Use a global variable to track the total number of cars
parked.

o Use local variables inside functions to:

 Accept car details.

 Calculate the parking fee based on hours parked.

o Task: Simulate parking for multiple cars and display


cumulative results.

9. Returning a Boolean Value for User Authentication


Scenario: Write a program that checks user login credentials:

o Function authenticateUser() should accept a username and


password.

o Compare with pre-stored credentials and return a boolean


value (true or false).
Task: Allow three login attempts. Display "Access Granted" or
"Access Denied" based on the result.

10. Global Constants and Local Variable Shadowing


Scenario: A program calculates the total electricity bill for a
household:

o Define a global constant for the electricity unit rate.

o Inside a function, declare a local variable with the same name


as the global constant.

o Calculate the bill using both values and demonstrate variable


shadowing.
Task: Clearly print the results to highlight the difference.

11. Pointer to Arrays for Dynamic Salary Management


Scenario: A company wants to manage employees' salaries. Write
a program to:

o Dynamically allocate an array to store n salaries using


pointers.

o Allow the user to update salaries for specific employees using


pointer arithmetic.

o Calculate and display the total payroll.


Task: Ensure proper memory management using new and
delete.
12. Array of Pointers for Student Name Management
Scenario: Write a program that stores and manipulates student
names using an array of pointers:

 Input names of n students (use dynamic memory allocation).

 Perform the following operations:

o Sort the names alphabetically.

o Search for a specific name entered by the user.


Task: Output the sorted list and the result of the search
operation.

Submission Guidelines:

 Submit the C++ source code for each task.


 Ensure that the program compiles and runs without errors.
 Include comments in your code explaining key steps.
 For each program, test it with multiple inputs and write down the
results.
 Provide screenshots of source code & input/output for verification as
pdf.
 Deadline: 28th December 2024.

You might also like