0% found this document useful (0 votes)
24 views3 pages

P Flab 12 Morning

Uploaded by

Shumyze Najam
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)
24 views3 pages

P Flab 12 Morning

Uploaded by

Shumyze Najam
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/ 3

Programming Fundamental LAB – Fall 2019

(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

Then, your program should display the following summary on screen:


No. of positive integers: 5
No. of negative integers: 2

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.

Task4: Consider the following InputFile_expression.txt:

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:

If file contain this:

Kamran Baig
Yousuf Kamal
Aslam Ali Chaudhry
Adil Saleem
Malik Nawaz Khan
Javed Rashid
Ali Usman

Then, your program should display the following on screen:

Smallest name is: Adil Saleem


Largest name is: Yousuf Kamal

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').

For Example, if the file words.txt contains:

Carry umbrella and overcoat when it rains.

Then the file vowel.txt shall contain

umbrella and overcoat.

Task7: Write a program in C to delete a specific line from a file

Assume that the content of the file test.txt is :


test line 1
test line 2
test line 3
test line 4
Example :
Input the file name to be opened : test.txt

Input the line you want to remove : 2

Expected Output :

The content of the file test.txt is :


test line 1
test line 3
test line 4

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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy