Write an application that accepts information for one product from the user. You
ID: 641776 • Letter: W
Question
Write an application that accepts information for one product from the user. Your application should be user-friendly and provide clear prompts to the user. The user should enter Item ID, item name, and item price. After the user has entered all three values, the application should display this information to the user. This allows the user to verify the information entered. The product information should display in an easy-to-read format using the appropriate combination of printf(), print() and println() statements. Headers or labels should be used in the display to make it clear what each value displayed represents.
Your code should be well commented.
Before you write your Java code, start your design by using pseudocode to outline your algorithm. Submit this algorithm in a Word document, and upload this with your zipped NetBeans project. This document will be the beginning of your design document for your application.
Explanation / Answer
#include #include #include "valid.c"struct purch_detail { char item_desc[20]; int unit_price; int qty; }; void display(); void entryData(); void readFile(); void getName(char *str); void getWriteFileName(char *); void getReadFileName(char *); void getzeroInteger(char *_chr, int *_value); int count=0; int total_price=0; int total_amt=0; char option; char filename [14]; FILE *fp; struct purch_detail *pd_ptr, *tmptr; void main() { clrscr(); pd_ptr = (struct purch_detail *) malloc(sizeof(struct purch_detail) * 10); tmptr = pd_ptr; printf(" Do you want to create the data file type 'y' for yes and 'n' for no."); scanf("%c", &option); fflush(NULL); if( option == 'y' || option == 'Y') { printf(" You can generate bill of maximum 10 item. "); getWriteFileName(filename); display(); } elseif( option == 'n' || option == 'N') { getReadFileName(filename); readFile(); } getch(); } void entryData() { while(1) { printf(" Enter item name : "); getName(tmptr->item_desc); getPosInteger("Enter unit price of the item : ", &tmptr->unit_price); getzeroInteger("Enter no of qty purchased : ", &tmptr->qty); if(tmptr->qty == 0) break; count ++; if (count >= 10) break; /* if ( count % 2 == 0) if ( (pd_ptr = (struct purch_detail *) realloc(pd_ptr, sizeof(struct purch_detail) * 2)) == NULL) { printf("Realloc failed. No enough memory available."); break; } */ tmptr++; } } void display() { tmptr = pd_ptr; fprintf(fp," Item Unit Price Quantity Total Price "); fprintf(fp," ______________________________________________________"); printf(" Item Unit Price Quantity Total Price "); printf(" ______________________________________________________"); while(1) { total_price = tmptr->unit_price * tmptr->qty ; fprintf(fp, " %-20s %4d %4d %5d", tmptr->item_desc, tmptr->unit_price, tmptr->qty, total_price); printf(" %-20s %4d %4d %5d", tmptr->item_desc, tmptr->unit_price, tmptr->qty, total_price); //printf(""); total_amt += total_price; count--; if ( count = 20 ) break; } fflush(NULL); if(errorflag) getName(str); *getstr=''; } void getzeroInteger(char *_chr, int *_value) { float tempval =1; int _ival=0; printf(" %s", _chr); _scaint = scanf("%f", &tempval); fflush(NULL); if ( _scaint != 0 ) { _ival = tempval; if ( tempval < 0 ) { printf("%s", " You should enter value greater then or equal to zero. Enter the value again..."); getzeroInteger(_chr, _value); } elseif ( _ival != tempval) { printf("%s", " Error(decimal value). It will be truncated the digit after the percision. Enter integer number only."); getzeroInteger(_chr, _value); } elseif( ! ( (tempval >= -32768 ) && (tempvalRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.