Instructions:: Assignment 3

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Assignment 3

Instructions:
1. You are strictly not allowed to use anything other than pointers and dynamic
arrays.
2. If plagiarism found, zero marks will be awarded.

Task 1
A 1D binary character array is given to you in file “task1.txt”. You are required to find out
maximum consecutive ones in the array.
Note: Read the file and find the exact length of data in a separate function. Use that size to
create a dynamic integer array using pointers. Then, read the file again and insert data into this
dynamic array of exact calculated size. Then You are required to find out maximum consecutive
ones in the array.

task1.txt.

11010101111110110111010

Expected output:
- maximum consecutive ones are: 111111
- Starting index is: 7
- Length is: 6

Task 2
Write a C++ program which reads text data line by line from a text file(Name: input.txt). A user
defined function is used to read data line by line from file (Name of function is ReadAllLines()).
After reading each line this line is passed to another function (Name: updateLine()) which counts
the No. of characters in line and insert no. of characters at the end of line and returns updated
line contents. First method (ReadAllLines()) writes this line in another text file(Name:
UpdatedInput.txt). Program also displays Total No. of characters found in File (Input.txt) at the
end.
Note: You will always pass a pointer of each line to function updateLine() method.
Output:

Input.txt UpdatedInput.txt
I am a student of UCP. I am a student of UCP. 22
I am in second Semester. I am in second Semester. 24
I am in Love with UCP. I am in Love with UCP.22
Output:
Total characters found in file are: 68

You might also like