0% found this document useful (0 votes)
2 views2 pages

Lab07 B

Uploaded by

abdulhamid.jamon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Lab07 B

Uploaded by

abdulhamid.jamon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

CS2311 Computer Programming 2024-25A

Lab 07-b File IO


Please test the correctness of your program in Q1, Q2 and Q3 on PASS.
Q-1.
Write a program in C++ to read the integers from a file named Q1input.txt,
calculate sum of them and then write the expected output to both screen
(standard output/console) and the file named Q1output.txt.
Sample Input:
Q1input.txt (Not changed by program):
1 2 3 4 5 6 8 9 10 23

Sample Output:
Screen Output:
Sum of 1 2 3 4 5 6 8 9 10 23 is 71

Q1output.txt (After program is run):


Sum of 1 2 3 4 5 6 8 9 10 23 is 71

Q-2.
Write a program that opens the file named Q2input.txt and counts the number of
characters ('a' - 'z' and 'A' - 'Z'), digits ('0'-'9'), and other characters in that file.
Print out the expected output on the screen.
Sample Input:
Q2input.txt
a s w d 1 2 3 ^ 2 * 2 d ) j # k > w ? | S I M - ! B W

Sample Output:
Screen Output:
The number of characters is 13
The number of integer numbers is 5
The number of other characters is 9

1/2
CS2311 Computer Programming 2024-25A

Q-3.
Write a program that reads a file name as a cstring (maximum of 15 characters,
including the filename extension) and counts the occurrence of letters that occur
in the file (count uppercase and lowercase versions of a letter as the same letter,
and ignore all other characters). Output the letters in alphabetical order and list
only those letters that occur in the input file. Write letters that occur in the input
file to the file named Q3output.txt.
Sample Input:
Q3input.txt
The quick brown fox jumps over the lazy dog 1234567890

Sample Output:
Screen Output:
Enter file name (maximum of 15 characters):
Q3input.txt
The occurrence of 'a' is 1
The occurrence of 'b' is 1
The occurrence of 'c' is 1
The occurrence of 'd' is 1
The occurrence of 'e' is 3
The occurrence of 'f' is 1
The occurrence of 'g' is 1
The occurrence of 'h' is 2
The occurrence of 'i' is 1
The occurrence of 'j' is 1
The occurrence of 'k' is 1
The occurrence of 'l' is 1
The occurrence of 'm' is 1
The occurrence of 'n' is 1
The occurrence of 'o' is 4
The occurrence of 'p' is 1
The occurrence of 'q' is 1
The occurrence of 'r' is 2
The occurrence of 's' is 1
The occurrence of 't' is 2
The occurrence of 'u' is 2
The occurrence of 'v' is 1
The occurrence of 'w' is 1
The occurrence of 'x' is 1
The occurrence of 'y' is 1
The occurrence of 'z' is 1

Q3output.txt (After program is run):


a b c d e f g h i j k l m n o p q r s t u v w x y z

2/2

You might also like