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

Programming Eight Batch Text File 77 - 80

Uploaded by

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

Programming Eight Batch Text File 77 - 80

Uploaded by

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

PROGRAMMING ASSIGNMENT

BATCH # 8
TEXT FILE

Task 77: Write a program with the following given options. For this program you are provided with text
file “City.txt” a sample of which is shown below. A sample screen shot of the file is shown below

(1) Print All


(2) Count Cities
(3) Add a City
(4) Search a City
(5) Delete a City
(6) Quit

Option 1 will print all the cities from the city file.

Option 2 will print how many cities are there in the city file.

Option 3 will add new record in the city file.

Option 4 will search whether a city a city exists in the file or not. Must write a
function that returns True or False.

Option 5 will ask the user a city to delete from the file and either print “City Deleted Successfully” or
print “City not found” if the city is not found in the file.

Task 78: In this task you will first make a file that follows the given format.

One Character Type of Parcel followed by weight of parcel.

S8.25

C4.2

E2.2

There are 3 types of parcels and you may assume that no invalid data will be saved in the text file.

You will be provided with a text file “parcel.txt” that you can use to test your program.

Now write a program with the following options.


(1) Print All Weights.
This option should print the Weight first then the type of parcels. You must use python
slicing to separate the weight from type.
(2) Search
In this option user will input a type, your program should print all the weight in this specific
type and also print how many how many parcels were found in this type of parcel.
(3) Find Average
This option should print the average weight of all the parcels.
(4) Cost of Parcels.
In this option you have to calculate the bill for all parcels and print the total bill.
Use the given rate list for the types
Type C : Rs. 250 per kg
Type S : Rs. 300 per kg
Type E : Rs. 350 per kg
An additional Basic cost of Rs. 50 is to be added to each parcel.
Print the bill for each parcel and finally print the total bill.
(5) Add
In this option the user will add a new weight in the file. Type and Weight will be input by
user. Save this data in the file.
(6) Quit

Task # 79 In this program you will use a text file “Products.txt” that will be provided to you. The format
used in this file will be one field per line and every record will consist of 5 fields.

Line 1 : product code


Line 2 : Product Name
Line 3 : Price
Line 4 : Current Stock Level
Line 5 : Minimum Stock Level
A sample is shown on the right.

Write a program with the following options.

(1) Print All products


This optino should all the records in the file. The output must be horizontal with each field in a
different column and heading to show the fields.
(2) Search Code :
This option will input a code to search in the file and then print all the other information of
the code if it is found. Print an error if not found.
(3) ReOrder:
This option will print the code and name of all the item in the file that have a current stock
level below the Minimum stock Level.
(4) Delete
This option will delete a product record from the file. The product must be searched with
the product code and if found delete the product details.
(5) Quit.

Task # 80: In this program you will use a text file Vehicle.txt with the fields of the file being saved in one
line in the given format.
<Vehcile ID><space><Make><comma><price> for example

1028 Civic,650000
The ID will be only 4 digits followed by a space. After the make there will be a comma to as a seperator.
Write a program with the following given options.

(1) Input
This option will allow the user to input data in the file. Take all the fields as input and make
it one line before writing.
(2) Print
This will print all the Vehicles in the file. Make sure to print fields seperately after removing
the seperator.
(3) Search
This option will search the Vehicle by its ID. Print the other fields if found, error otherwise.
(4) Delete
Allow the user to delete a vehicle record using the Vehicle ID.
(5) Most Expensive
Print the details of the car that is most expensive.
(6) Average Price
Print the Average Price of the Vehicle in the file.
(7) Quit

You might also like