0% found this document useful (0 votes)
4 views2 pages

Lab 1

The document outlines a lab assignment consisting of five tasks related to C++ programming. Tasks include defining an Employee structure, implementing functions for salary management, string operations without the cstring library, pointer usage, and input validation within specified limits. Each task requires specific programming implementations and user interactions to demonstrate understanding of the concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Lab 1

The document outlines a lab assignment consisting of five tasks related to C++ programming. Tasks include defining an Employee structure, implementing functions for salary management, string operations without the cstring library, pointer usage, and input validation within specified limits. Each task requires specific programming implementations and user interactions to demonstrate understanding of the concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Lab 1

Target: CLO-1

CLO 1 2 3 4 5
CLO-1 2-marks for 2-marks for 2-marks for 2-marks for 2-marks for
task1 task2 task3 task4 task5

Task: 1
Define a structure named Employee with members for employee ID, name, and salary.

Create a function named InitializeEmployee that takes a reference to an Employee structure and
initializes its members with values provided by the user. Write a function named FindMaxSalary that
takes an array of Employee structures and its size as parameters. The function should find and return
the employee with the maximum salary.

Create a function named CalculateAverageSalary that takes an array of Employee structures and its
size as parameters. The function should calculate and return the average salary of all employees.

Write a function named UpdateSalary that takes an Employee structure and a percentage increase as
parameters. The function should update the salary of the employee based on the provided
percentage increase.

Implement a function named PrintEmployeeInfo that takes an Employee structure as a parameter


and prints its members' information in formatted output to the console.

In the main program:

• Declare an array of Employee structures named companyEmployees with a size of 3.

• Use a loop to initialize the members of each employee in the array.

• Call the FindMaxSalary function to find and print the details of the employee with the
maximum salary.

• Call the CalculateAverageSalary function and print the average salary.

• Update the salary of one employee using the UpdateSalary function.

• Print the information of all employees using the PrintEmployeeInfo function.

Task: 2
Write a function that will take two pointers of integer arrays of fixed size. The function will return 0 if
both the arrays are same and return -1 otherwise. Call the function from main to check its
functionality. The function declaration is given below:

int compare(int *a, int *b);

Task: 3
Implement a C++ program that explores various string operations without utilizing the cstring library.
Your task is to create the following functions: Calculates the length of a given string. Concatenates
two strings. Compares two strings. Copies the content of one string to another.

In the main function:


Declare two character arrays (str1 and str2) with a maximum length of 100 characters. Prompt the
user to input two strings, ensuring proper handling to prevent buffer overflow.

Utilize the implemented functions to:

• Calculate and display the length of each string.


• Concatenate the two strings and display the result.
• Compare the two strings and display the result.
• Copy the contents of the first string to a new string and display it.

Ensure your program handles user input appropriately, and limit the length of input strings to
prevent buffer overflow.

Task: 4
Write a C++ program that creates and initialize 3 variables of different types, create pointers for each
variable and access those variables using pointer references and show memorysize of each variable
using (sizeof ()) function.

Task: 5
Handling Upper Limits in C++

Write a C++ program that prompts the user to input a number within a specified range. Implement
the following:

1. Set a lower limit (LOWER_LIMIT) and an upper limit (UPPER_LIMIT) for the allowed input range.

2. Use a while loop to repeatedly prompt the user until a valid input within the specified range is
provided.

3. If the user enters an invalid input (not a number or outside the specified range), display an error
message and prompt again.

4. Once a valid input is received, display the entered value.

You are not allowed to use the <limits> library for this task. Test your program with different inputs
to ensure it handles upper limits correctly.

You might also like