P Flab 12 Morning
P Flab 12 Morning
(MSc-CS-F19 Morning)
Lab # 12
Instructions:
Indent your code properly.
Use meaningful variable names. Use camelCase notation.
Use meaningful prompt lines/labels for all input/output.
Task1: You have a text file (numbers.txt) which contains several positive and negative integers. You don’t know the number of
integers in the file.
Write a C++ program which reads the file numbers.txt and displays on screen showing the number of positive integers and the
number of negative integers present in the file.
For Example:
If the file “numbers.txt” contains:
36
11
5
-85
23
-11
478
Task2: Write a function to count number of words in a text file named “words.txt".
Task3: Assuming that a text file named words.txt contains some text written into it, write a function named convertUpper(),
that reads the file words.txt and creates a new file named capital.txt contains all words from the file words.txt in uppercase.
23
+ 24
-3
*6
/9
%7
+ 12
This file contains arithmetic operators and operands. You are required to extract operands and operator to perform
arithmetic operation. You will keep extracting data unless you get end of file and display the result after performing
all arithmetic operations. You are required to write and use following functions to perform arithmetic operations:
int sum ( int first , int second); // takes two integer parameters and returns their sum
int difference (int first , int second); // takes two integer parameters and returns their difference
int product (int first , int second); // takes two integer parameters and returns their product
int quotient (int first , int second); // takes two integer parameters, performs division, returns quotient.
int remainder (int first , int second); // takes two integer parameters, performs division and returns remainder
Output: 23+24–3*6/9%7+12 = 13
Task5: You have a text file (names.txt) which contains several names (one on each line). You are also told that maximum length
of any name would be 50 characters, and a name might contain spaces in it. Note that the exact number of names in the file is
not known.
You are required to write a C++ program which should read all names from the above file, and determine the name which is
alphabetically smallest and the name which is alphabetically largest. At the end, your program should display these two names
on screen.
For Example:
Kamran Baig
Yousuf Kamal
Aslam Ali Chaudhry
Adil Saleem
Malik Nawaz Khan
Javed Rashid
Ali Usman
Note: you are not allowed to use String data type in this task.
Hint: You can use stringLength and stringComparison functions which you have done in your assignment.
Task6: Assuming that a text file named words.txt contains some text written into it, write a function named vowelWords(),
that reads the file words.txt and creates a new file named vowel.txt, to contain only those words from the file words.txt which
start with a lowercase vowel (i.e., with 'a', 'e', 'i', 'o', 'u').
Expected Output :
Task8: Write a function that takes input in an array from user. Then pass this array to another function which displays an array
in reverse order. Assign memory dynamically after asking size from user.
Note: You are not allowed to use subscript operator [ ].
Hint: Use dereference operator for this.