(5/5)

# Write a program that takes a person’s details (name, age and a city), and writes to a file (persons.txt) using a loop repeatedly.

INSTRUCTIONS TO CANDIDATES

All the problems listed below must be solved by writing a pseudocode and by writing program code with documentation (using comments). Each problem is worth 10 marks. Documentation is worth 4 marks and the program code 6 marks.

1. Write a program that takes a person’s details (name, age and a city), and writes to a file (persons.txt) using a loop repeatedly. You should write three person’s to the file. The program terminates on entering any key by the user, except on (Y or y) key.  Sample output of the first run of the program is shown below:

Enter name: John

Enter age: 20

Enter city: Sydney

Data saved:  John 20 Sydney

Press (Y or y) to add another person, or any key to exit

2. Write a program that read a file (persons.txt) from previous question -Q1, and shows all the records/lines from the file as a nicely formatted report with a header as shown:

Name                   Age                      City

+---------------------+--------------------+--------------

3. The body mass index (BMI) is calculated as a person’s weight (KG) divided by the square of the person’s height (in inches). A BMI in the range 19-25 (inclusive) is considered healthy. Write a program that calculates a person’s BMI and prints a message telling whether they are above, within, or below the healthy range. This program must keep on calculating BMI for the given input till user says, “they don’t want to continue”.

Hint: use a while loop and ask the user if they want to calculate BMI. If the answer is “Yes”, continue with calculations. If the answer is “No” quit the program.

Example:

Input:

Height = 1.78 m

Weight = 102 KG

Process:

BMI = 102 / (1.78*1.78) = 32.2

Output:

Your BMI is 32.19. You are obese. Lose weight to live longer.

See https://bmicalculatoraustralia.com/ for an example BMI calculator.

4. Write a simple guessing that generates a random number between 1 and 7 and asks the user to guess the number. If the user guess (input value) matches the program’s random number. It prints “Congratulations! You won” else prints “Sorry Try again”.  Use a loop so that the user gets to play the game repeatedly unless the user decides to quit.

Example – If the program’s random number is 6 and the user guess number is 5.

(5/5)

## Related Questions

##### . Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

##### . The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

##### . Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

##### . SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

##### . Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Hire Me