Amani A.

asked • 01/31/22

I need help in my homework in c language.

1) Define a structure type called PersonCar of three fields: a person name (pName), a car model (cModel) two strings and a car price (price) a real number.

2) Declare pc an array of 4 PersonCars, c an integer number of registered cars in the system initially zero, and npc a pointer to struct PersonCar initially NULL that will point to a dynamically allocated array and represents the total cars registered or not in the system. These 3 variables pc, c, and npc are declared as global variables. Give the segment names where these variables are stored in.

3) In the main program, the user is requested to enter the number of cars to register less than or equal to 4. The user then enters his name and the car models and prices that will be stored in pc. The system can register many persons and their cars as long as there is a space in the system (only 4).

2

Dr. Charbel Rahhal 2020 - 2021


4) Define a function float calculatePrice(struct PersonCar *p, char *name) that takes as parameters a pointer to a structure PersonCar and a person name, calculates and returns the total price of the registered cars for the given person.

5) Define a function void changeName(struct PersonCar *p, char *currentName, char *newName, char * gender) that changes the name of a person in the array of registered cars PersonCars p. If the person is a male then the current name becomes new name in p. If she is a female with a name starting with “Miss”, the function removes Miss from the name and adds her husband’s surname newName to the end the female’s name in p.

Example: “Miss Rose” and husband’s last name is “Miller” then her name becomes “Rose Miller”.

3

Dr. Charbel Rahhal 2020 - 2021


6) Define a function struct PersonCar* changeTotalCars(void) that will be executed only if the total number of registered cars in the system c = 4, asks the system’s owner to enter an integer nnc > 4 and a new array of PersonCars of size nnc will be dynamically allocated in the system and its address is stored in variable npc previously declared in question 1). All the registered cars in array pc will be copied into npc. The function then asks the user to enter the number of cars to register in the system. If there is enough space in npc, the user name, cars models and prices will be entered and stored in npc otherwise it returns NULL.

7) A person sold his car so it will be removed (person name, car model, and price) from the system. Define a function struct PersonCar * deletePersonCar(char * persName, char * carModel) that deletes the car of model carModel for the person persName from the array npc after resizing it. The function will return a pointer to the new array. Remember to decrease the number of registers cars c by 1.

Example of calling this function: npc = deletePersonCar(“May”, “BMW”);

1 Expert Answer

By:

Jeff B. answered • 02/01/22

Tutor
5.0 (832)

Master's degree in Computer Science and 6+ years industry experience

Amani A.

very helpful thnx alot . but what about the other parts , they are more complicated
Report

02/01/22

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.