Professional Documents
Culture Documents
Department of Information Systems and Technologies Spring 2020 - 2021
Department of Information Systems and Technologies Spring 2020 - 2021
The %s operator is one used for reading strings of characters in to character arrays using the scanf function.
a) Initialize the data with the following values (Brand: Mercedes, ModelYear: 2017, MotorPower: 2.0, Km: 134.00, Price: 384.50),
and then display as shown in the example run.
Example Run:
The Car information is:
Brand : Mercedes
Model Year : 2017
Motor Power : 2.0
Kilometer : 134.00
Price : 384.50 TL
Project Name: LG4_Q1a
File Name: Q1a.cpp
b) Get the structure data from the user, and then display as shown in the example run.
Example Run:
Enter the information of the car:
Brand : Audi
Model Year : 2016
Motor Power : 1.8
Kilometer : 105
Price : 495
2. Amazon offers special discount for some products. Discounted products’ information (product name, price, discount rate)
is kept in the “amazon.txt” file.
Write a C program that will read all the products’s information from the file into a dynamically created structure array,
display the product information including the discounted price and the saved amount. The program will also display the
number of products.
( Use dynamic memory allocation for the structure array. The first line of the file consists the number of products. )
AQ2. A media company keeps the track of radios which serve from the internet. The company needs a program that stores the
information of the radios: Frequency, name of the radio, number of hits of the most popular program for each. Write the
following functions;
read gets the radio information from a file into an array of structures.
display displays all radio information as in the example run.
findMaxHits returns the index of the radio which has the maximum number of hits.
findRadio finds the radio information with the given frequency and returns the index of this radio.
Write a main program that takes the number of inputs (n) from the user and read the information for n radios from the
file “radio.txt” into the array of structure which you created dynamically. Maximum size is 20 for inputs. Do NOT forget
to make data validation. If you don’t use dynamic memory allocation, you will lose points.
The program will also do the followings;
Display the list of all radios,
Find and display the radio which has the maximum hits.
Ask for a frequency and display the radio information which has this frequency.
Please examine the given example runs, and test your programs.
Hints:
Use %s operator while reading and displaying the radio name.
Include stdlib.h for malloc()
Example Run#1
How many radio information will you read: 30 Sorry! There is no radio on the given frequency
Error!!! Please enter a number 1-20 :(
The radio <Alemfm> has the maximum hits Radio <Showradyo> is on the 89.8 frequency
Frequency: 89.2
Hits : 98210 Project Name: LG4_AQ2
Enter a radio frequency to search: 100.0 File Name: AQ2.cpp