Programming Fundamentals: Lab 08 - A10
Programming Fundamentals: Lab 08 - A10
Programming Fundamentals
Task 1:
Write a C++ program to take three float values from user as input. If the multiplication of first and
third input is greater than second input, firstly add 15 in first and third variables then subtract 5 from
first and third variables to display sum of these two values on console but if the If the multiplication
of first and third input is less than or equal to second input, firstly subtract 3 from first and third
variables then add 31 in first and third variables to display difference of these two values on console.
The whole task should be done through pointers after initializing or declaring variables.
Example 1:
Input:
Enter Number 1: 11.5
Enter Number 2: 55.9
Enter Number 3: 4.6
Output:
Difference (11.5,55.9,4.6) = 6.9
Example 2:
Input:
Enter Number 1: 11.5
Enter Number 2: 55.9
Enter Number 3: 9.6
Output:
Sum (11.5,55.9,9.6) = 41.1
Task 2:
Write a C++ program in which, read integers from a file “input.txt” into an integer array. Now Find the
second maximum and second minimum number from array using pointers and display them on
console.
Example:
Input:
Input.txt: 10 2 5 7 6 8 4 9 11 13
Output:
Maximum Number: 13
Minimum Number: 4
Task 3:
Write a C++ program in which, read words from a text file “input1.txt” into a character array one by
one. Now find the length of word using pointers and store the word and its size into a file “output.txt”.
Example:
Input:
Input1.txt
Hello
World
Happy
Sad
Luck
Output:
output.txt
Hello 5
World 5
Happy 5
Sad 3
Luck 4
Task 4:
Write a C++ program in which read numbers from a file “input2.txt”. Replace first half elements of
array with the last half elements using pointers, and vice versa. Display the array before and after
replacement. File contains maximum 20 numbers.
Example:
Output:
Before Replacement:
Array A:
5 4 3 2 1 10 9 8 7 6
After replacement:
Array A:
10 9 8 7 6 5 4 3 2 1
Task 5:
Write a C++ program in which, read integers from file “input3.txt” into an integer array and an integer
Key. Pass the array as parameter of function along with address of key and array size which received
the array into a pointer in which, if the key is found then return the address of that element. If key is
not found than return the address of 5th element. You can pass any extra parameter if required.
Note: The Address (X120 and X160) are given here as example.
Example 1:
Input:
Array = {1,2,3,4,5,6,7,8,9,11,13,14}
Enter the value of Key: 8
Output:
The Address for 8 in Array = X160
Example 2:
Input:
Array = {1,2,3,4,5,6,7,8,9,11,13,14}
Enter the value of Key: 21
Output:
The Address of fifth element = X120
Submission guidelines:
1. Zip 5 .cpp files and .txt files as mentioned in tasks.
2. File name should only be “Lab”.
3. The Submission deadline will be Sunday 11:59 PM (02-05-2021).