Question

Create a c program of your choosing that follows the specifications below: Define a struct with...

Create a c program of your choosing that follows the specifications below:

  • Define a struct with 4 or more members. The struct must be different from the ones used in class (20 points)
  • Declare an array of your struct using a size of 10 or more (20 points)
  • Load the data for each element in your array from a text file (20 points)
  • Display the data in your array in the terminal (20 points)
  • Provide brief comments for every line of code (20 points)
  • Please be creative
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

#include <stdio.h>

//Defined a struct car with 4 members

struct car{

char maker[100];

char model_name[100];

int model_year;

float price;

};

//Display the data in your array in the terminal (20 points)

//Provide brief comments for every line of code (20 points)

int main(void) {

//Declared an array of struct car with a size of 10

struct car arr[10];

//To read the details from a file crated a file pointer

FILE *fp;

//opend a file named cars_details in read mode

fp = fopen("cars_details.txt","r");

//reading from file and storing in array named arr

for(int i=0;i<10;i++){

fscanf(fp,"%s %s %d %f",arr[i].maker,arr[i].model_name,&arr[i].model_year,&arr[i].price);

}

//printing to terminal

for(int i=0;i<10;i++){

printf("Maker:%s Model:%s Release_year:%d Price:%.2f Lakhs\n",arr[i].maker,arr[i].model_name,arr[i].model_year,arr[i].price);

}

return 0;

}

car_details.txt

cars_details.txt 1 2. 3 4 5 6 7 8 9 10 Audi RS7_Sportback 2019 194 Honda City 2019 14.64 Hyundai Tucson 2019 27.03 MG Hector_

output:

Maker:Audi Model:RS7_Sportback Release_year:2019 Price:194.00 Lakhs
Maker:Honda Model:City Release_year:2019 Price:14.64 Lakhs
Maker:Hyundai Model:Tucson Release_year:2019 Price:27.03 Lakhs
Maker:MG Model:Hector_Plus Release_year:2019 Price:18.54 Lakhs
Maker:Honda Model:WR-V Release_year:2019 Price:8.50 Lakhs
Maker:Mercedes-Benz Model:GLS Release_year:2019 Price:100.00 Lakhs
Maker:BMW Model:X6 Release_year:2019 Price:95.00 Lakhs
Maker:Datsun Model:Redi_GO Release_year:4 Price:0.77 Lakhs
Maker:Mercedes-AMG Model:GT Release_year:2019 Price:227.00 Lakhs
Maker:Skoda Model:Superb Release_year:2019 Price:32.99 Lakhs

Add a comment
Know the answer?
Add Answer to:
Create a c program of your choosing that follows the specifications below: Define a struct with...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • please help!!! this is VMware Workstation, thank you! Create a c program of your choosing that...

    please help!!! this is VMware Workstation, thank you! Create a c program of your choosing that follows the specifications below: • Define a struct with 4 or more members. The struct must be different from the ones used in class (20 points) Declare an array of your struct using a size of 10 or more (20 points) Load the data for each element in your array from a text file (20 points) Display the data in your array in the...

  • Exercise #6: ------------ - Define a struct of your own that uses several different data types...

    Exercise #6: ------------ - Define a struct of your own that uses several different data types for the members. {At least 3.} - Create a structure of that type and: - place values into it's members - print the values of each member in the structure - Write a display function that displays the contents of your struct type

  • Main topics: Files Program Specification: For this assignment, you need only write a single-file ...

    C program Main topics: Files Program Specification: For this assignment, you need only write a single-file C program. Your program will: Define the following C structure sample typedef struct int sarray size; the number of elements in this sanple's array floatsarray the sample's array of values sample Each sample holds a variable number of values, all taken together constitute a Sample Point Write a separate function to Read a file of delimited Sample Points into an array of pointers to...

  • ***************C PROGRAMMING ONLY************* Demonstrate the ability to create an array on the stack Demonstrate the ability...

    ***************C PROGRAMMING ONLY************* Demonstrate the ability to create an array on the stack Demonstrate the ability to create an array on the heap allowing user to choose the number of values to store. Demonstrate the ability to store an array of Struct values on both the stack and the heap. Program Specifications: 1. Create a struct with at least 3 fields - any struct you want but explain it in your comments in the code. Populate at least 10 elements...

  • Activities Define a struct called Unit containing the following fields I Unit code Unit credit hours...

    Activities Define a struct called Unit containing the following fields I Unit code Unit credit hours Unit semester of study List of prerequisites Number of prerequisites List of post requisites Number of post requisites Inside your main function declare an array of type Unit called units with size 20 elements. This array will contain the information related to all the units in our diploma program. Each of the elements of this array correspond with one our diploma units. II III...

  • The language is C++. Code needs to be added to line 28 and 37. Could someone...

    The language is C++. Code needs to be added to line 28 and 37. Could someone provide some help with how to do it? CODE Write a program to unscramble words A file with list of words is provided along with a template program to get you started. 1. Define a struct with 2 string members: sorted and original 2. Declare an array of 200000 elements with data type of the struct 3. Read from a file a list of...

  • Problem Specification: Write a C++ program to calculate student’s GPA for the semester in your class. For each student, the program should accept a student’s name, ID number and the number of courses...

    Problem Specification:Write a C++ program to calculate student’s GPA for the semester in your class. For each student,the program should accept a student’s name, ID number and the number of courses he/she istaking, then for each course the following data is needed the course number a string e.g. BU 101 course credits “an integer” grade received for the course “a character”.The program should display each student’s information and their courses information. It shouldalso display the GPA for the semester. The...

  • In c++ Write a program that contains a class called Player. This class should contain two...

    In c++ Write a program that contains a class called Player. This class should contain two member variables: name, score. Here are the specifications: You should write get/set methods for all member variables. You should write a default constructor initializes the member variables to appropriate default values. Create an instance of Player in main. You should set the values on the instance and then print them out on the console. In Main Declare a variable that can hold a dynamcially...

  • Need the c code please, also please only use <stdio.h> library. Simple code please Define a...

    Need the c code please, also please only use <stdio.h> library. Simple code please Define a struct with teg Capacitor that holds the following Information about a capacitor: Model number (e.g. 11-123U), capacitance (e.g. 1000 u.f), voltage (e.g. 2.5 V), cost {$6.50} Create your main program file capacltorsInfac. Declare two variables of type struct Capacitor and populate them with the following values: First' variable: model Is 11-123U, capacitance Is 100, voltage Is 25 and cost Is $6.00 Second variable: model...

  • I have homework that asks to create C++ program to include: 1A) Create and populate a...

    I have homework that asks to create C++ program to include: 1A) Create and populate a parallel-array Data Structure using the following code: //Student grade records are stored in a parallel-array Data Structure. //Here is the code to generate and populate //the Parallel-Array Data Structure: const int NG = 4; //Number of Grades string names[] = {"Amy Adams", "Bob Barr", "Carla Carr", "Dan Dobbs", "Elena Evans" }; int assessment[][NG]= { {98,87,93,88}, {78,86,82,91}, {66,71,85,94}, {72,63,77,69}, {91,83,76,60} };    1B) Define a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT