Find the source code below. I have tested the code so i have provided lines for printing for testing purpose as well.They are commented out. Uncomment and you see result.Comment if any doubt.
Note - Create input file ITEMS.txt and place it in same folder. See screenshot.
#include <stdio.h>
#include<stdlib.h>
typedef struct grocery{
char name[20],type[15];
float cost,taxp;
int quan;
}grocery;
int main(void) {
grocery g[50];
/************part a ***************/
FILE* file;
if((file=fopen("ITEMS.txt","r"))==NULL){
printf("Error in opening file");
exit(1);
}
int count=0;
while(
fscanf(file,"%s %s %f %d
%f",g[count].name,g[count].type,&g[count].cost,&g[count].quan,&g[count].taxp)!=EOF){
//printf("%s|%s|%f|%d|%f\n",g[count].name,g[count].type,g[count].cost,g[count].quan,g[count].taxp);
count++;
}
/************part b ***************/
//sort
int i;
for(i=1;i<count;i++){
int j=1;
while(j>=1 &&
g[j].cost>g[j-1].cost){
grocery temp=g[j-1];
g[j-1]=g[j];
g[j]=temp;
}
}
/*
//print sorted list
printf("printing sorted list\n");
for(i=0;i<count;i++){
printf("%s|%s|%f|%d|%f\n",g[i].name,g[i].type,g[i].cost,g[i].quan,g[i].taxp);
}*/
/*********part c**********/
FILE* fw;
if((fw=fopen("ITEMS.bin","w"))==NULL){
printf("can not open file to write");
}
fwrite(g,sizeof(grocery),count,fw);
grocery f[50];
fclose(fw);
/*printf("read from file\n");
FILE* fr=fopen("ITEMS.bin","r");
fread(f,sizeof(grocery),count,fr);
for(i=0;i<count;i++){
printf("%s|%s|%f|%d|%f\n",f[i].name,f[i].type,f[i].cost,f[i].quan,f[i].taxp);
}*/
return 0;
}
==================================Sample input file=====
ITEMS.txt
Apple
Fruit
12.34 12 10.5
Milk
Drinks
24 2 5
=======================================
![Files clang-7 -pthread -lm -o main main.c ./main с main.c L ITEMS.bin L ITEMS.txt } main.c saved 5 char name[20], type[15]; 6](http://img.homeworklib.com/questions/5ba457f0-58ef-11eb-a0f4-5dbafbddbe80.png?x-oss-process=image/resize,w_560)
Hi the programming language for this assignment is C programming. Could you also please number the...
Use
c++ as programming language. The file needs to be created ourselves
(ARRAYS) Write a program that contains the following functions: 1. A function to read integer values into a one-dimensional array of size N. 2. A function to sort a one-dimensional array of size N of integers in descending order. 3. A function to find and output the average of the values in a one dimensional array of size N of integers. 4. A function to output a one-dimensional...
C++ programming language Write a program that asks the user for a file name. The file contains a series of scores(integers), each written on a separate line. The program should read the contents of the file into an array and then display the following content: 1) The scores in rows of 10 scores and in sorted in descending order. 2) The lowest score in the array 3) The highest score in the array 4) The total number of scores in...
The Code need to be in C# programming language. could you please leave some explanation notes as much as you can? Thank you Create the following classes in the class library with following attributes: 1. Customer a. id number – customer’s id number b. name –the name of the customer c. address – address of the customer (use structs) d. telephone number – 10-digit phone number e. orders – collection (array) of orders Assume that there will be no more...
programming language is C++. Please also provide an explanation of
how to create a file with the given information and how to use that
file in the program
Let's consider a file with the following student information: John Smith 99.0 Sarah Johnson 85.0 Jim Robinson 70.0 Mary Anderson 100.0 Michael Jackson 92.0 Each line in the file contains the first name, last name, and test score of a student. Write a program that prompts the user for the file name...
Using C programming For this project, you have been tasked to read a text file with student grades and perform several operations with them. First, you must read the file, loading the student records. Each record (line) contains the student’s identification number and then four of the student’s numerical test grades. Your application should find the average of the four grades and insert them into the same array as the id number and four grades. I suggest using a 5th...
In C++ Programming Write a program in Restaurant.cpp to help a local restaurant automate its breakfast billing system. The program should do the following: Show the customer the different breakfast items offered by the restaurant. Allow the customer to select more than one item from the menu. Calculate and print the bill. Assume that the restaurant offers the following breakfast items (the price of each item is shown to the right of the item): Name Price Egg (cooked to order)...
Please use C Programming language (Not C++)
7.6 LAB*: Warm up: Online shopping cart (Part 1) (1) Create three files to submit: • Item ToPurchase.h - Struct definition and related function declarations • Item ToPurchase.c-Related function definitions • main.c-main function Build the ItemToPurchase struct with the following specifications: • Data members (3 pts) • char itemName • int itemPrice • int itemQuantity • Related functions • MakeltemBlank0 (2 pts) Has a pointer to an item To Purchase parameter. Sets item's...
Could anyone please help with this Python code assignment? In this programming assignment you are to create a program called numstat.py that reads a series of integer numbers from a file and determines and displays the following: The name of the file. The sum of the numbers. The count of how many numbers are in the file. The average of the numbers. The average is the sum of the numbers divided by how many there are. The maximum value. The...
Question: C Programming Problem: Pointer and Struct Description: The purpose of this assignment is to prov... C Programming Problem: Pointer and Struct Description: The purpose of this assignment is to provide practice programming using structs and pointers. Your program will accept user input and store it in a dynamic array of structs. First, you will define a structure to describe a item to be bought. Your program will prompt the user for the initial size of the array. It will...
Programming Assignment 1 Structures, arrays of structures, functions, header files, multiple code files Program description: Read and process a file containing customer purchase data for books. The books available for purchase will be read from a separate data file. Process the customer sales and produce a report of the sales and the remaining book inventory. You are to read a data file (customerList.txt, provided) containing customer book purchasing data. Create a structure to contain the information. The structure will contain...