Вы находитесь на странице: 1из 4

Lab 2 PF Fall ‘19

University of Central Punjab


Faculty of Information Technology

PF Lab 2

 Use appropriate variable and function names


 Use functions where necessary
 There are total 7 questions in this manual
 Use exact file names as mentioned in questions

Question 1
Write a C++ program that takes 2 input integers from file “numbers.txt” and outputs their
sum in file “result.txt”.
Sample “numbers.txt”:
15 28
Sample “result.txt”:
43

Question 2
Write a C++ program that reads a list of names from file “names.txt”. You must display the
names on console that are present in the file. Assume max length for name is 50 characters.
Sample “names.txt”:
Ali Akram Butt
Ahmad Usman
Ayesha Mumtaz
Amjad Khan
Ch. Bilal Masood

1
Lab 2 PF Fall ‘19

Question 3
Write a C++ program that copies contents of file “input.dat” to file “output.dat”.

Question 4
Write a C++ program that reads integers from file “integers.txt” and outputs the total
number of primes and their count in “primes.txt”. You may assume input file will not have
more than 25 integers and that total count of numbers is given at start of file.
Sample “integers.txt”:
10 13 99 200 41 47 51 100 6 5 93
Sample “primes.txt”:
4 13 41 47 5

Question 5
Write a C++ program that takes input from user and appends it to file “Students.txt”. File
contains students’ marks. You should display entire file after a new student record is added.
Each instance of your program should only add 1 entry to the record file. Data to be added is
as follows: Student name, student roll number, and student CGPA.
Sample “students.txt”:
Ali Akram, L1F19BSCS0001, 3.23
Amna Shahbaz, L1F20BSCS0002, 3.98
Zubair Ahmad, L1F19BSCS0121, 2.67

User input:
Name: Ashfaq Chaudhry
Roll number: L1F18BSCS0444
CGPA: 3.2

After appending data:


Ali Akram, L1F19BSCS0001, 3.23
Amna Shahbaz, L1F20BSCS0002, 3.98
Zubair Ahmad, L1F19BSCS0121, 2.67
Ashfaq Chaudhry, L1F18BSCS0444, 3.2

2
Lab 2 PF Fall ‘19

Question 6
Write a C++ program that searches/displays the record of a student based on their roll
number. I.e. function that accepts as parameter a roll number and prints the relevant
student data on screen.
Note: roll number is an integer in this scenario
Sample “students.txt”:
Ali Akram, 0001, 3.23
Amna Shahbaz, 0002, 3.98
Zubair Ahmad, 0121, 2.67
Ashfaq Chaudhry, 0444, 3.2

Roll number entered:


0444
Sample output:
Ashfaq Chaudhry, 0444, 3.2

Question 7
Write a C++ program that merges 2 files “input1.txt” and “input2.txt” line by line in a new
file “output.txt”. If one file ends you must simply output the remaining file to output file.
Sample input:
Input1.txt
Alpha beta
Gamma omega
Extra
Lines
And redundant

Input2.txt
Are not
But are

3
Lab 2 PF Fall ‘19

Sample output:
Alpha beta
Are not
Gamma omega
But are
Extra
Lines
And redundant

Вам также может понравиться