0% found this document useful (0 votes)
10 views

Class-Assignment-4_FA24

Assignment

Uploaded by

maryyamsaeed011
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Class-Assignment-4_FA24

Assignment

Uploaded by

maryyamsaeed011
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

COMSATS University Islamabad

Department of Computer Science


Programming Fundamentals (CSC103) – BSDS-2A
Class Assignment – 4

CLO-3: Handle programs utilizing exception and file I/O.

Due Date: December 18, 2024 (11:59 pm)

Total Marks: 10

Instructions
Answers to all questions must be submitted in PDF Format.

Assignment document must contain a title page showing Assignment-3, your name and
registration number.

Assignment document must also contain JAVA source code along with output.

The Solution of this assignment must be a single program which will be menu based.
You must follow proper JAVA naming convention for identifiers and properly document your
source code.

The name of the Assignment document file should be your Registration Number. E.g.
FA21BCS01.pdf

Submit your work via MS Teams which include a single JAVA file and pdf report along with
output.

Plagiarism: Plagiarism is not allowed. If found plagiarized, zero marks will be awarded in the
assignment.
COMSATS University Islamabad
Department of Computer Science
Programming Fundamentals (CSC103) – BSDS-2A
Class Assignment – 4

Question - 1:
Write a program to create a file named Text_IO.txt if it does not exist. Append new data to it if it
already exists. Write 100 integers created randomly into the file using text I/O. Integers are
separated by a space.

Question - 2:

Write a program that will count the number of characters, words, and lines in a file. Words are
separated by whitespace characters. The file name should be passed as a command-line argument.

Question - 3:
The popularity ranking of baby names from years 2015 to 2018 is downloaded from
https://www.ssa.gov/oact/babynames/ and stored in files named babynameranking2015.txt, . . . ,
babynameranking2018.txt. Each file contains one thousand lines. Each line contains a ranking, a
boy’s name, number for the boy’s name, a girl’s name, and number for the girl’s name. For
example, the first few lines in the file babynameranking2018.txt are as follows:

So, the boy’s name Liam and girl’s name Emma are ranked #1. Write a program that prompts the
user to enter the year, gender, and followed by a name, and displays the ranking of the name for
the year. Here is a sample run:
Enter the year: 2018
Enter the gender: M
Enter the name: Alexander
Alexander is ranked #11 in year 2018
COMSATS University Islamabad
Department of Computer Science
Programming Fundamentals (CSC103) – BSDS-2A
Class Assignment – 4
Question - 4:

Write a program to read integers from a file, calculate their sum, and log any errors (e.g., non-
integer values) to a separate error log file. Your program must:

• Skip invalid entries and continue processing the file.


• Log errors with specific details (e.g., line number, invalid value).

Display the total sum of valid integers.

Question - 5:

Write a program to search for a specific word in a large text file. The program must:

• Read the file line by line to avoid memory issues with large files.
• Track the line numbers where the word appears.
• Handle exceptions for missing or unreadable files.
• Output the word's occurrences and line numbers, or a message if the word is not found.

You might also like