Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The program uses both files and arrays. The Problem Statement Your friend is starting a new business. She's gotten access to discounts all over town

The program uses both files and arrays.

The Problem Statement

Your friend is starting a new business. She's gotten access to discounts all over town from stores, restaurants, and more. She's been selling her discounts to students but is having trouble keeping tabs on who owes her money. She's offered you a 20% cut of her total revenue to build a program that will track each student she sells to, the sale price of each item, and the amount of money she's collected from that person.

Scaffolds

You will be provided with a program scaffold to complete for this assignment. Scaffolds, also called skeleton code, are programs that already have some of the solution completed. Do not modify the code that is already present. Instead, fill in the sections that are maked like this: /*** ... ***/

Download the scaffold here: accounts_scaffold.cimage text in transcribedimage text in transcribed

Program Description

Your program will read information from an input from a file that stores information about every transaction you friend makes. You may assume that your roommate has no more than 100 customers and each customer is labeled 0 through 99. An array has already been created to store information about these customers.

Your program will need to respond to three different commands:

Add a payment

Sell an item

Print messages for negative accounts

For commands of types 1 and 2, your program should update the appropriate customer account. A command of type one adds value to the account and a command of type two subtracts value from an account.

For commands of type 3, you should print out a message with the following format for each customer (in order of customer number) that has a negative account balance:

Customer X, you owe $Y. Please pay immediately!

where X is the account number and Y is the number of dollars owed (a positive amount).

If all accounts are paid properly, then print out the single line:

All accounts are paid up to date!!!

These commands will come from an input file.

Input File Format

The first line of the input file contains a single positive integer, n (n 1000), representing the number of commands to process. The commands follow, one per line.

Each command line will start with an integer, 1, 2 or 3, corresponding to the types of commands listed above. For command types 1 and 2, this will be followed with a space and a second integer, ID (0 ID 99), representing the identification number of the customer for the transaction. This will be followed by another space and a positive integer, v (v 100), representing the amount of dollars for the transaction. Commands of type 3 will have no further information following them.

Specification

Homework assignments are either correct or incorrect. Do not modify any of the printf statements in the scaffold. Do not add any printf statements to the program.

accounts_scaffold.c

#include

#define MAX_CUSTOMERS 100

int main() { // declare variables int numCommands, i, accounts[MAX_CUSTOMERS]; int command, id, amount, j, ok; char filename[20]; /***Declare File Pointer***/

// Open file. printf("What is the name of the file? "); scanf("%s", filename); /***Open Input File***/

// Initialize accounts. /***Set all values in accounts to zero***/

// Read the number of commands from the file fscanf(ifp, "%d", &numCommands);

// Process each command. for (i=0; i

// Get type of this command. /***Read command value from file***/

// Add money. if (command == 1) { /***Read id and amount from file***/ accounts[id] += amount; }

// Subtract money. else if (command == 2) { fscanf(ifp, "%d %d", &id, &amount); /***Deduct amount from the account with identification number id***/ }

// Print delinquents. else { // Go through each account, flagging negative balances. ok = 1; for (j=0; j

// Best case scenario. if (ok) printf("All accounts are paid up to date!!! ");

} }

/***close file pointer***/

return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Fundamentals Study Guide

Authors: Dr. Sergio Pisano

1st Edition

B09K1WW84J, 979-8985115307

More Books

Students also viewed these Databases questions

Question

4 How the market system adjusts to change and promotes progress.

Answered: 1 week ago