Question

This program will reinforce our knowledge on basic ‘C’ program control, arrays, and editing and compiling...

This program will reinforce our knowledge on basic ‘C’ program control, arrays, and editing and compiling ‘C’ programs.

The objective of this assignment is to create a program that tallies a shopping list of items and displays each selected item, item cost, and total cost of all the selected items plus tax. The program will setup a simple sporting goods store with a few items and prices. The user will submit a shopping list in a textfile and submit it to the program as a command line argument.

Requirements:

The program will setup two arrays – one for the store items and another for each price. The following table indicates the store items and prices:

Item: Price:

Cooler 32.75

Tent 158.23

Fishing Pole 23.25

Flashlight 15.35

Sleeping Bag 45.00

Camping Stove 61.55

Rope 4.25

Bottled Water 5.45

Bug Spray 3.25

Sunblock 7.90

First Aid Kit 12.45

Raincoat 22.35

The program will accept 1 command line argument that indicates the file name of a text-based file that contains a shopping list.

Each line of this file indicates the item to be purchased. The maximum length of the list is 20. The list of items will be zero based.

The program should process the shopping list and print the list out to the screen with each item and price on a separate row. At the end of the list the total cost with 5.5% tax added to it should be displayed.

You must make use of functions in this assignment. At least one of the functions must have parameters.

There must be arrays within the code.

Use good programming practice and check for array out of bounds errors and handle them appropriately

Example:

File: shoppingList.txt

1

2

2

3

3

3

2

ShoppingList.txt file is the actual list of items to be purchased – 0 based. So the first digit ‘1’ indicates a Tent, the digit ‘2’ indicates a Fish Pole, etc… If a digit ‘0’ were present it would indicate a Cooler.

NOTE: A different list than the one above for testing the code.

Program Output:

Shopping List:

Tent $158.23

Fishing Pole $23.25

Fishing Pole $23.25

Flashlight $15.35

Flashlight $15.35

Flashlight $15.35

Fishing Pole $23.25

Total with tax: $289.10

0 0
Add a comment Improve this question Transcribed image text
Answer #1

main.c

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

int main(int argc, char *argv[])
{
//file declarations
//FILE *fp = fopen("C:/Users/Apple/Desktop/shoppingList.txt", "r");
FILE *fp = fopen(argv[0], "r");


//arrays declaration for item and price
char *item[]={"Cooler", "Tent", "Fishing Pole", "Flashlight", "Sleeping Bag", "Camping Stove", "Rope", "Bottled Water", "Bug Spray", "Sunblock", "First Aid Kit","Raincoat"};
float price[]={32.75, 158.23, 23.25, 15.35, 45.00, 61.55, 4.25, 5.45, 3.25,7.90, 12.45, 22.35 };

int len=0,n;
float total=0.0, tax;

//check if file exits
if (!fp){
printf("\n source file does not exits");
return 1;
}

printf("\nShopping List:\n");
//read the shopping list and print the item and price in the screen
for(len=0;fscanf(fp,"%d",&n)!= EOF ; len++)
{
total+=price[n]; //calculate the total price
printf("\n%s $%.2f",item[n],price[n]);

}
tax=total + total* 0.055; //add tax to the total price
printf("\nTotal with tax: $%.2f", tax);

return 0;
}

output:

İ DYcpplshoppingListibin\Debug\ShoppingList.exe Shopping List: Tent $158.23 Fishing Pole $23.25 Fishing Pole $23.25 lashlight

//for any clarification or modification,please do commnets

Add a comment
Know the answer?
Add Answer to:
This program will reinforce our knowledge on basic ‘C’ program control, arrays, and editing and compiling...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Assignment: Write a program in C++ that allows a customer to go on-line shopping. This is...

    Assignment: Write a program in C++ that allows a customer to go on-line shopping. This is a start-up venture and the stock of our on-line company is currently limited to the following items: A gift card to Home Depot, $50.00 A bottle of cologne (The One by Dolce Gabbana), $24.00 3. Akeychainwithabathtubornament,$14.00 4. Acard,$4.00 Although all items are in stock, the customer should only be made aware of the items that he or she can afford. In addition, demand for...

  • In C++ Programming Write a program in Restaurant.cpp to help a local restaurant automate its breakfast...

    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)...

  • Use the C programming language to complete #include <stdio.h> #include <stdlib.h> #include <float.h> // Declare Global...

    Use the C programming language to complete #include <stdio.h> #include <stdlib.h> #include <float.h> // Declare Global variables here. void array_stats() { // Insert your solution here. } #include <stdlib.h> #include <time.h> int main() { // Simulate the test setup process. srand( time( NULL ) ); for ( int i = 0; i < 32; i++ ) { val[i] = rand(); } val_count = rand(); val_mean = rand(); val_min = rand(); val_max = rand(); // Call submitted code. array_stats(); // Display...

  • Edit a C program based on the surface code(which is after the question's instruction.) that will...

    Edit a C program based on the surface code(which is after the question's instruction.) that will implement a customer waiting list that might be used by a restaurant. Use the base code to finish the project. When people want to be seated in the restaurant, they give their name and group size to the host/hostess and then wait until those in front of them have been seated. The program must use a linked list to implement the queue-like data structure....

  • Write a c++ program in that file to perform a “Search and Replace All” operation. This...

    Write a c++ program in that file to perform a “Search and Replace All” operation. This operation consists of performing a case-sensitive search for all occurrences of an arbitrary sequence of characters within a file and substituting another arbitrary sequence in place of them. Please note: One of the biggest problems some students have with this exercise occurs simply because they don’t read the command line information in the course document titled “Using the Compiler’s IDE”. Your program: 1. must...

  • Needs Help with Java programming language For this assignment, you need to write a simulation program...

    Needs Help with Java programming language For this assignment, you need to write a simulation program to determine the average waiting time at a grocery store checkout while varying the number of customers and the number of checkout lanes. Classes needed: SortedLinked List: Implement a generic sorted singly-linked list which contains all of the elements included in the unsorted linked list developed in class, but modifies it in the following way: • delete the addfirst, addlast, and add(index) methods and...

  • Lab 6 Instructions Objectives: • Executing and experimenting with programs that handle array related topics such...

    Lab 6 Instructions Objectives: • Executing and experimenting with programs that handle array related topics such as declaration, initialization, storing, retrieving, and processing elements. • Effectively manipulating and using ArrayList objects. • Becoming familiar with the use of arrays as method arguments and how array elements are passed to and returned from the called method. • Mastering the use of various debugging tools available on the Eclipse IDU. Important: EVERY one of the following Activities MUST be in a separate...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT