[go: up one dir, main page]

0% found this document useful (0 votes)
47 views5 pages

File IO Questions

The document contains four programming questions focusing on file input/output operations. Question 1 involves counting digits in a string written to a file, Question 2 requires converting speed from km/h to m/s and writing the result to a new file, Question 3 deals with determining whether potato seeds can be planted based on their weight, and Question 4 asks for printing words without vowels from a string stored in a file. Each question includes input/output formats, constraints, and sample test cases.

Uploaded by

jetblackaqua957
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)
47 views5 pages

File IO Questions

The document contains four programming questions focusing on file input/output operations. Question 1 involves counting digits in a string written to a file, Question 2 requires converting speed from km/h to m/s and writing the result to a new file, Question 3 deals with determining whether potato seeds can be planted based on their weight, and Question 4 asks for printing words without vowels from a string stored in a file. Each question includes input/output formats, constraints, and sample test cases.

Uploaded by

jetblackaqua957
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/ 5

FILE INPUT/OUTPUT/READ/WRITE QUESTIONS

QUESTION 1

Problem Statement

John is working on a project where he needs to count the number of digits in a


given string. He writes the string to a file and then reads the file to calculate
the total number of digits. The program should output the count of digits found in
the file.

File Name: output.txt

Input format :
The input consists of a string.

Output format :
The output prints the number of digits in the given string.

Refer to the sample output for formatting specifications.

Code constraints :
The maximum length of the string is 100.

Sample test cases :


Input 1 :
Phone number : 8976578011
Output 1 :
10
Input 2 :
Hi, Six is written as 6.
Output 2 :
1

QUESTION 2

Problem Statement
Nick is developing a program to convert speed units from kilometers per hour (km/h)
to meters per second (m/s). However, he needs assistance in creating a structured
and user-friendly program.

Create a file named data.txt to enter the speed in km/h as given in the input. The
program reads the speed from data.txt and then converts the speed from km/h to m/s
using the formula. The converted speed is written to a new file named converted.txt
and then displayed.

Formula: speed in meters per second = speed in km per hour * 5.0 / 18.0.

Input format :
The input consists of a double value D, representing the speed in kilometers per
hour (km/h).

Output format :
The output prints a double value followed by "m/s" representing the converted speed
in meters per second (m/s) with two decimal places.

Refer to the sample output for formatting specifications.

Code constraints :
1.0 ≤ D ≤ 360.0

Sample test cases :


Input 1 :
180.0
Output 1 :
50.00 m/s
Input 2 :
58.0
Output 2 :
16.11 m/s
Input 3 :
360.0
Output 3 :
100.00 m/s

QUESTION 3
Problem Statement

On his property, a farmer is sowing potato seeds. He thinks that everything about
his plants' growth and good output comes from nature. If the weight of each potato
is divisible by five, he can plant it in the ground for growth. Otherwise, change
the seed to acquire a good harvest.

Write the array into a file named output.txt and create a method to monitor seed
quality and assist the seed company in making more money.

Input format :
The first line of input consists of an integer N, representing the number of seeds.

The second line consists of N space-separated integers, representing the values of


their grams.

Output format :
The output prints the type of seed that can be planted or changed for each of the N
values in one of the following formats:

If the seed is changed, print "Change X gram seed" where X is the value of the
grams.
If the seed is planted, print "Plant X gram seed" where X is the value of the
grams.

Refer to the sample output for the formatting specifications.

Code constraints :
1 ≤ N ≤ 50

1 ≤ Each value of grams ≤ 100

Sample test cases :


Input 1 :
5
23 12 7 2 5
Output 1 :
Change 23 gram seed
Change 12 gram seed
Change 7 gram seed
Change 2 gram seed
Plant 5 gram seed
Input 2 :
10
68 21 65 23 98 57 25 49 96 94
Output 2 :
Change 68 gram seed
Change 21 gram seed
Plant 65 gram seed
Change 23 gram seed
Change 98 gram seed
Change 57 gram seed
Plant 25 gram seed
Change 49 gram seed
Change 96 gram seed
Change 94 gram seed

QUESTION 4

Problem Statement

Write a program to obtain a string and write it to a file. Read the file contents
and print the words that do not contain vowels.

File Name: output.txt

Input format :
The input consists of a string.

Output format :
The output consists of the words without vowels, each printed on a separate line.

Refer to the sample output for a better understanding.

Code constraints :
The input string contains 100 characters.

Sample test cases :


Input 1 :
Don't be too shy
Output 1 :
shy
Input 2 :
Try to listen to the rhythm of your heart
Output 2 :
Try
rhythm

You might also like