Starting from:
$30

$24

Computer Programming Lab #9 Solution


Write a single program which realizes the following tasks.

    1. The program should have a struct called ‘line’.



‘line’ struct should keep 7 float variables. The first 6 variables are for the 3 different points on a line: (x1, y1), (x2, y2) and (x3, y3). The last value is the slope of the line. A line is defined as y = m*x+b where m is called the slope.


        ◦ User enters x1, y1, x2, y2 and x3. The program keeps these values in a line struct. It should also calculate both slope and y coordinate of the third point (y3) and fill their values in the struct. Furthermore, the program prints these two calculated values.

    2. The program should have two structs called ‘grades’ and ‘students’.

        ◦ ‘grades’ struct should keep 3 float variables: midterm, final and homework.

        ◦ ‘students’ struct should keep a string (for name and surname), an integer (for id number) and a grades struct to keep the grades of the related student.

User enters the inputs for each student: name-surname, id number and 3 different grades (user decides the number of the students). The program should keep all of these in an array of students struct. Once the user enters all of the information, the program should save the average of each grade in a grades struct and then print them. Lastly, the program asks user to enter an id number and print the information of the student who has that id number (if there is no-one with that id number the program should give an error message).

    3. The program should have a struct called ‘games’.

    • ‘games’ struct should have the following values: a string for the name of the game, a string array for the platforms (e.g. PC, PS4, mobile etc.) to play that game and a float variable for the score of the game.

User enters the inputs for each game (The number of the games to enter and the number of the platforms for each game is decided by the user). The program should keep these values in an array of games struct. Once the user enters all the information, the program prints the followings:

    • Average of the scores of the games.

    • The lists of the games for each platform. For example; PS4 games: The Last of Us, Dying Light, Until Dawn.

General rules:
    • For the third part, string.h is allowed. Beside this, you are not allowed to use any libraries other than stdio.h.

    • You can write your own functions for a clean code.
    • You can use other variables, arrays etc. to make things easier.

    • Don’t use dynamic allocation. You can decide the lengths of the arrays, e.g., 20 characters for a game’s name.

    • To read a string which includes spaces, use following codes:

fflush(stdin); scanf("%[^\n]%*c", string);

More products