Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define ROWS 100
- #define SIZE_OF_STIRNG 100
- int main();
- void getUserChoice(int*);
- void addStockEntry();
- void purchaseStocks();
- void sellStocks();
- void displayStocks();
- void displaySales();
- void displayPurchases();
- void clearWindow();
- void evaluateChoice(int);
- void mainMenu();
- void generateTestData();
- void columnTables();
- int itemCodeArray[ROWS];
- char itemNameArray[ROWS][SIZE_OF_STIRNG];
- float unitPriceArray[ROWS];
- int discountLevelsArray[ROWS]; //discount level is the number of items of he product the customer has to buy to be eligible to receive the discount
- float discountRateArray[ROWS];
- int currentStockArray[ROWS];
- int purchaseCodeArray[ROWS];
- int purchaseItemCodeArray[ROWS];
- int purchaseAmounts[ROWS];
- float purchaseNetTotalArray[ROWS];
- int salesCodeArray[ROWS];
- int salesItemCodeArray[ROWS];
- int salesAmounts[ROWS];
- float salesNetTotalArray[ROWS];
- float salesSubTotalArray[ROWS];
- int lastItemCode = 0;
- int lastPurchaseCode = 0;
- int lastSalesCode = 0;
- void generateTestData(){
- char gItemNames[3][SIZE_OF_STIRNG] = {"Apples","Pineapples","Oranges"};
- float gUnitPrices[3] = {50,100,40};
- float gDiscLevels[3] = {150,200,300};
- float gDiscRates[3] = {20,25,10};
- int gCurrStocks[3] = {10,20,50};
- for(int i = 0;i<3;i++){
- itemCodeArray[i] = i+1;
- strcpy(itemNameArray[i],gItemNames[i]);
- unitPriceArray[i] = gUnitPrices[i];
- discountLevelsArray[i] = gDiscLevels[i];
- discountRateArray[i] = gDiscRates[i];
- currentStockArray[i] = gCurrStocks[i];
- lastItemCode = i+1;
- }
- int gPurchItemCodes[3] = {1,2,3};
- int gPurchAmounts[3] = {5,10,15};
- for(int i = 0;i<3;i++){
- purchaseCodeArray[i]=i+1;
- purchaseAmounts[i] = gPurchAmounts[i];
- purchaseItemCodeArray[i] = gPurchItemCodes[i];
- purchaseNetTotalArray[i] = gPurchAmounts[i] * unitPriceArray[gPurchItemCodes[i]-1];
- lastPurchaseCode = i+1;
- }
- int gSalesItemCodes[3] = {1,2,3};
- int gSalesAmounts[3] = {5,10,15};
- for(int i =0;i<3;i++){
- salesCodeArray[i] =i+1;
- salesItemCodeArray[i] = gSalesItemCodes[i];
- salesAmounts[i] = gSalesAmounts[i];
- salesNetTotalArray[i] = gSalesAmounts[i] * unitPriceArray[gSalesItemCodes[i]-1];
- salesSubTotalArray[i] = ( salesNetTotalArray[i] >= discountLevelsArray[gSalesItemCodes[i]-1] ) ?
- salesNetTotalArray[i] * (1 - discountRateArray[gSalesItemCodes[i]-1]/100.0) :
- salesNetTotalArray[i];
- lastSalesCode = i+1;
- }
- }
- void mainMenu(){
- printf("Welcome to the inventory Management System\n");
- printf("\t\t\tMAIN MENU\n");
- printf("\t1. Add new stock entry\n");
- printf("\t2. Record Purchases \n");
- printf("\t3. Record Sales\n");
- printf("\t4. View Sales details\n");
- printf("\t5. View Purchase details\n");
- printf("\t6. View Stock Details\n");
- printf("\t9. Exit Program\n");
- }
- void getUserChoice(int* userChoice){
- printf("Enter choice to continue: ");
- scanf("%d",userChoice);
- }
- void addStockEntry(){
- printf("Entering item data for item code %d\n",lastItemCode+1);
- itemCodeArray[lastItemCode] = lastItemCode + 1;
- printf("Enter item name: ");
- scanf("%s",itemNameArray[lastItemCode]);
- int isUnitPriceZero = 1;
- while(isUnitPriceZero){
- printf("Enter item unit price: ");
- scanf("%f",&unitPriceArray[lastItemCode]);
- if(unitPriceArray[lastItemCode] == 0 && unitPriceArray[lastItemCode] > 0){
- printf("Unit price can not be zero\n");
- }else{
- isUnitPriceZero = 0;
- }
- }
- printf("Enter item discount levels: ");
- scanf("%d",&discountLevelsArray[lastItemCode]);
- printf("Enter item discount rates(Enter the percentage e.g. to represent 15%% input 15): ");
- scanf("%f",&discountRateArray[lastItemCode]);
- printf("Enter current stock: ");
- scanf("%d",¤tStockArray[lastItemCode]);
- lastItemCode += 1;
- }
- void purchaseStocks(){
- int inputItemCode = 0;
- int inputAmount = 0;
- printf("Entering purchase code: %d\n",lastPurchaseCode+1);
- printf("Enter item code: ");
- scanf("%d",&inputItemCode);
- if(inputItemCode <= lastItemCode){
- int isAmountZero = 1;
- while(isAmountZero){
- printf("Enter amount: ");
- scanf("%d",&inputAmount);
- if(inputAmount == 0){
- isAmountZero = 1;
- }else{
- isAmountZero = 0;
- }
- }
- purchaseCodeArray[lastPurchaseCode] = lastPurchaseCode+1;
- purchaseItemCodeArray[lastPurchaseCode] = inputItemCode;
- purchaseAmounts[inputItemCode-1] = inputAmount;
- purchaseNetTotalArray[inputItemCode-1] = purchaseAmounts[inputItemCode-1] * unitPriceArray[inputItemCode-1];
- currentStockArray[inputItemCode-1]=currentStockArray[inputItemCode-1]+inputAmount;
- lastPurchaseCode += 1;
- }
- else
- printf("invalid item code.\n");
- }
- void sellStocks(){
- int inputItemCode = 0;
- int sellingAmount = 0;
- printf("Entering sales code: %d\n",lastSalesCode+1);
- printf("Enter item code: ");
- scanf("%d",&inputItemCode);
- if(inputItemCode <= lastItemCode){
- int isAmountZero = 1;
- while(isAmountZero){
- printf("Enter amount: ");
- scanf("%d",&sellingAmount);
- if(sellingAmount == 0){
- isAmountZero = 1;
- }else{
- isAmountZero = 0;
- }
- }
- if(sellingAmount>currentStockArray[inputItemCode-1])
- {
- printf("not enough stock available to complete the order\n");
- }
- else
- {
- salesCodeArray[lastSalesCode] = lastSalesCode+1;
- salesItemCodeArray[lastSalesCode] = inputItemCode;
- salesAmounts[lastSalesCode] = sellingAmount;
- salesNetTotalArray[inputItemCode-1]= sellingAmount * unitPriceArray[inputItemCode-1];
- //discountArray[lastItemCode]=(sellingAmount>=discountLevelsArray[lastItemCode])?salesNetTotalArray[lastItemCode]*discountRateArray[lastItemCode]/100:0;
- //salesSubTotalArray[lastItemCode]=salesNetTotalArray[lastItemCode]-discountArray[lastItemCode];
- salesSubTotalArray[inputItemCode-1] = ( salesNetTotalArray[inputItemCode-1] >= discountLevelsArray[inputItemCode-1] ) ?
- salesNetTotalArray[inputItemCode-1] * (1 - discountRateArray[inputItemCode-1]/100.0) :
- salesNetTotalArray[inputItemCode-1];
- currentStockArray[inputItemCode-1]=currentStockArray[inputItemCode-1]-sellingAmount;
- lastSalesCode+=1;
- }
- }
- }
- void displayStocks(){
- //labels
- for(int j =0;j<80;j++){
- printf("_");}
- printf("\n");
- printf("item name |");
- printf(" item code |");
- printf("unit price |");
- printf("discount level|");
- printf("discount rate|");
- printf("current stock|");
- printf("\n");
- for(int k =0;k<80;k++)
- printf("_");
- printf("\n");
- for(int i=0;i<lastItemCode;i++){
- printf("%10s | ",itemNameArray[i]);
- printf("%10d | ",itemCodeArray[i]);
- printf("%10.2f | ",unitPriceArray[i]);
- printf("%12.2f | ",discountLevelsArray[i]);
- printf("%11.2f%%| ",discountRateArray[i]);
- printf("%11d | ",currentStockArray[i]);
- printf("\n");
- }
- }
- void displaySales(){
- for(int j=0;j<lastItemCode;j++){
- for(int i =0;i<lastSalesCode;i++){
- if(itemCodeArray[j] == salesItemCodeArray[i]){
- printf("%10d | ",salesCodeArray[i]);
- printf("%10d |",salesItemCodeArray[i]);
- printf("%11s |",itemNameArray[salesItemCodeArray[i]-1]);
- printf("%10.2f | ",unitPriceArray[salesItemCodeArray[i]-1]);
- printf("%10d |",salesAmounts[i]);
- printf("%10.2f | ",salesNetTotalArray[i]);
- printf("%10.2f |",salesSubTotalArray[i]);
- printf("\n");
- }
- }
- }
- }
- void displayPurchases(){
- //labels
- for(int j =0;j<80;j++)
- printf("_");
- printf("\n");
- printf("purchase code|");
- printf(" item code |");
- printf(" item name |");
- printf(" unit price |");
- printf(" no. of items|");
- printf(" net total|");
- printf("\n");
- for(int k =0;k<80;k++)
- printf("_");
- printf("\n");
- for(int j=0;j<lastItemCode;j++){
- for(int i =0;i<lastPurchaseCode;i++){
- if(itemCodeArray[j] == purchaseItemCodeArray[i]){
- printf("%10d | ",purchaseCodeArray[i]);
- printf("%10d |",purchaseItemCodeArray[i]);
- printf("%11s |",itemNameArray[purchaseItemCodeArray[i]-1]);
- printf("%10.2f | ",unitPriceArray[purchaseItemCodeArray[i]-1]);
- printf("%10d |",purchaseAmounts[purchaseItemCodeArray[i]-1]);
- printf("%10.2f | ",purchaseNetTotalArray[purchaseItemCodeArray[i]-1]);
- printf("\n");
- }
- }
- }
- }
- void clearWindow(){
- system("cls||clear");
- }
- void evaluateChoice(int userChoice){
- clearWindow();
- switch (userChoice)
- {
- case 1:
- addStockEntry();
- break;
- case 2:
- purchaseStocks();
- break;
- case 3:
- sellStocks();
- break;
- case 4:
- displaySales();
- break;
- case 5:
- displayPurchases();
- break;
- case 6:
- displayStocks();
- break;
- case 9:
- printf("Exiting the program");
- exit(0);
- break;
- default:
- printf("INVALID CHOICE\n");
- break;
- }
- }
- int main(){
- generateTestData();
- int userWantstoContinue = 1;
- int userChoice = 0;
- while(userWantstoContinue){
- char yesOrno = ' ';
- clearWindow();
- mainMenu();
- getUserChoice(&userChoice);
- evaluateChoice(userChoice);
- printf("Do you want to continue using the software (y/n): ");
- scanf(" %c",&yesOrno);
- if(yesOrno == 'y'|yesOrno == 'Y'){
- userWantstoContinue = 1;
- }else{
- userWantstoContinue = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement