ROW JAURU

ROW JAURU

  • NA
  • 1
  • 1.4k

Need help programming c

May 8 2012 12:41 AM

I got an assigment that I need help with and I'm hoping that someone could give me some help with it. Here is what it's asking: 

The data file contains lines of text, some of which are tab-delimited price entries, while others are text.
Each price line is easily distinguished by the fact that it begins with a digit. Each price line has an Intel CPU's
current price, followed by a tab character, followed by the CPU's name.
Begin by defining a struct type that can store a CPU name and its price. Write a C program that includes
three separate functions:
1. read_price_list() reads the price list from the data file and stores it in an array of your structs,
2. sort_price_list() sorts the price list by decreasing price,
3. write_price_list() writes the sorted price list into a new data file Sorted_Price_List.txt.
The sorted price list file must contain only sorted price data: a CPU price, followed by a tab, followed by the
CPU's name; one CPU per line.


Here is what we have to sort:

Intel® Processor Pricing
Effective Apr 29, 2012
Recommended Customer Price Tray Units

Intel® Core™ i7 processor Extreme Edition Desktop (LGA2011)
999i7-3960X (15M cache, 6 Cores, 12 Threads, 3.30 GHz, 32nm)

Intel® Core™ i7 processor Desktop (LGA2011/1155)
583i7-3930K (12M cache, 6 Cores, 12 Threads, 3.20 GHz, 32nm)
294i7-3820 (10M cache, 4 Cores, 8 Threads, 3.60 GHz. 32nm)
332i7-3770K (8M cache, 4 Cores, 8 Threads, 3.50 GHz. 22nm)
294i7-3770 (8M cache, 4 Cores, 8 Threads, 3.40 GHz. 22nm)
332i7-2700K (8M cache, 4 Cores, 8 Threads, 3.50 GHz, 32nm)
317i7-2600K (8M cache, 4 Cores, 8 Threads, 3.40 GHz, 32nm)
294i7-2600 (8M cache, 4 Cores, 8 Threads, 3.40 GHz, 32nm)

Intel® Core™ i5 processor Desktop (LGA1155)
225i5-3570K (6M cache, 4 Cores, 4 Threads, 3.40 GHz, 22nm)
205i5-3550 (6M cache, 4 Cores, 4 Threads, 3.30 GHz, 22nm)
184i5-3450 (6M cache, 4 Cores, 4 Threads, 3.10 GHz, 22nm)
225i5-2550K (6M cache, 4 Cores, 4 Threads, 3.40 GHz, 32nm)
216i5-2500K (6M cache, 4 Cores, 4 Threads, 3.30 GHz, 32nm)
205i5-2500 (6M cache, 4 Cores, 4 Threads, 3.30 GHz, 32nm)
195i5-2450P (6M cache, 4 Cores, 4 Threads, 3.20 GHz, 32nm)
184i5-2400 (6M cache, 4 Cores, 4 Threads, 3.10 GHz, 32nm)
177i5-2380P (6M cache, 4 Cores, 4 Threads, 3.10 GHz, 32nm)
177i5-2320 (6M cache, 4 Cores, 4 Threads, 3.00 GHz, 32nm)
177i5-2310 (6M cache, 4 Cores, 4 Threads, 2.90 GHz, 32nm)

There's more to sort but it takes up alot of space.

And he gave us a skeleton source file:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct {
/* fill in */
} price_entry;

/* Reads a price list from a file and stores it in an array of structs.
Returns the number of price entries read from the file. */

int read_price_list(const char* input_name, price_entry* list, int list_size) {
/* only lines beginning with a digit contain price entries, ignore all other lines */
/* fill in */
}

int compare_price_entries(const price_entry* entry1, const price_entry* entry2) {
/* fill in */
}

/* Sorts a price list by decreasing price. */

void sort_price_list(price_entry* list, int list_size) {
/* use qsort() in conjunction with the compare_price_entries above, or write your own sort algorithm */
/* fill in */
}

/* Writes a price list into a new file. */

void write_price_list(const price_entry* list, int list_size, const char* output_name) {
/* fill in */
}

int main() {
int entry_count;
entry_count = read_price_list("Apr_29_12_Recommended_C… /* fill in */);
sort_price_list(/* fill in */);
write_price_list(/* fill in */, "Sorted_Price_List.txt");
return 0;
}

I've been working on in since Wed and I am completely stuck and any kind of help would be appreciated.

Answers (2)