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

Lab Task 2

Uploaded by

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

Lab Task 2

Uploaded by

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

University of Haripur

Department of Information Technology

Fall Semester

LAB Task: 1 - 2
Course Title : Data Structures & Algorithms Course Code: SWE-202
Course Inst : Javeria Naz Date 2-Oct-2023
Note:

 Submission Instructions: Please ensure that your name, section, and your student ID
number are legibly written and clearly visible on the front of your submission.
 Submission Format: You have to submit in Soft form.
 Late Penalty: Late task will not be accepted.

a. Create a C++ program using a class and functions to add six user-input
values to the end of an array. The array initially holds three pre-assigned
values. Afterward, display the complete array, including all nine values.
Functions name should be: Assign, Display and Input. Also write
Algorithm.

b. Write a program to delete a number from the end of array. Also write
Algorithm.

c. Given the string "Hello, World!", write a program to reverse only the
words in the string, not the entire string USING stack implemented using
array. For example, "Hello, World!" should become "olleH, dlroW!".
Also write Algorithm.

d. Consider the following algorithm, write the code to delete an element


from the specific location of array entered by user.
Algorithm:
1. Create an array of integers.
2. Initialize a variable size to store the current size of the array.
3. Prompt the user to input the size of the array and the elements.
4. Check if the size is greater than 0 and within the valid index range.
5. If the size is greater than 0 and the specified index is within the valid
range:
a. Display the current elements of the array.
b. Prompt the user to input the index of the element to be deleted.
c. Check if the specified index is valid (between 0 and size-1).
d. If the index is valid, delete the element by shifting elements to
the left.
e. Decrement the size by 1 to reflect the removal.
f. Display a message indicating the removed element.
6. If the size is 0 or the specified index is invalid, display appropriate
messages.
e. Write a program that display the largest number from a 2D-array:
Max[3][3]. Also find and display the sum of array elements. Also write
Algorithm.

_________________________________

You might also like