for the program im writing this is what i have to do:
i have to write a C program that maintains a table of productID and price in a .txt file.
The following menu shows the functionality of the program:
1. Display all products
2. Search product by ID
3. Sort the product list by price
4. Sort the product list by ID
5. List the average price
6. List max and min price
7. Exit
Specifications:
1. The product IDs and product prices are stored in a table format in a file named
products.txt. Create a text file in the same folder as your .c file and type in two columns
(ID and price) separated by a tab. product ID and price are integers
2. Main program will be main.c. Define the following functions in func.h and func.c files
(refer to lab 5, question 1).
displayMenu( ): displays the menu options 1. -7. on the screen, and asks the user
to ‘Enter an option:’.
readFile ( ) – opens the file ‘products.txt’ and reads contents from the file is read
in to a 2-D array named ‘products’.
displayProducts ( ) – displays the contents of the products list
searchProduct( ) – searches for a product by its ID and displays whether it is
found or not.
sortProductsPrice ( ) – sorts the products list in ascending order of the price, and
displays the sorted list
sortProductsID ( ) – sorts the products list in ascending order of the ID, and
displays the sorted list
averagePrice ( ) – calculates and displays the average price
maxMinPrice( ) – calculates the maximum and minimum price in the list and
displays the max and min values
so far i have this i dont know how to take input from a .text file helpp!!
#include <stdio.h>
#include <stdlib.h>
void displayMenu();
void readFile();
void displayProducts();
void searchProduct();
void sortProductsPrice();
void sortProductsID();
void averagePrice();
void maxMinPrice();
int main(int argc, char *argv[])
{
int userChoice = 0;
printf("Inventory Program\n\n");
displayMenu();
printf(" \nPick an option\n");
scanf("%d",&userChoice);
switch(userChoice)
{
case 1: displayProducts();
break;
case 2: readFile();
break;
case 3: searchProduct();
break;
case 4: sortProductsPrice();
break;
case 5: sortProductsID();
break;
case 6: averagePrice();
break;
case 7: maxMinPrice();
break;
}
system("PAUSE");
return 0;
}
void displayMenu()
{
printf("1 To Display Products Enter 1\n");
printf("2 To Extract Products From Txt File Enter 2\n");
printf("3 Search By Product I.D Enter 3 \n");
printf("4 Search And Sort Product By Prices 4\n");
printf("5 Search And Sort By Product I.D Enter 5\n");
printf("6 Search Average Price Enter 6\n");
printf("7 Calculate Maximum And Minimum Prices And Displays Them 7\n");
}
void readFile()
{
}
void displayProducts()
{
}
void searchProduct()
{
}
void sortProductsPrice()
{
}
void sortProductsID()
{
}
void averagePrice()
{
}
void maxMinPrice()
{
}