Computer Programming Lab3 - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

Computer Programming Lab3

Description:

Total of all credits applied to the customer's account this month; Allowed credit limit. ... For those customers whose credit limit is exceeded, the problem ... – PowerPoint PPT presentation

Number of Views:67
Avg rating:3.0/5.0
Slides: 9
Provided by: shyhka
Category:

less

Transcript and Presenter's Notes

Title: Computer Programming Lab3


1
Computer ProgrammingLab3
  • Shyh-Kang Jeng
  • Department of Electrical Engineering/
  • Graduate Institute of Communication Engineering
  • National Taiwan University

2
Lab Exercise 2 Department Store (1/2)
  • Develop a C program that will determine if a
    department-store customer has exceeded the credit
    limit on a charge account. For each customer,
    the following information is available
  • Account number (an integer)
  • Balance at the beginning of the month
  • Total of all items charged by the customer this
    month
  • Total of all credits applied to the customers
    account this month
  • Allowed credit limit.

3
Lab Exercise 2 Department Store (2/2)
  • The program should input this information,
    calculate the new balance (beginning balance
    charges credits) and determine if the new
    balance exceeds the customers credit limit. For
    those customers whose credit limit is exceeded,
    the problem should display the customers account
    number, credit limit, new balance and the message
    Credit limit exceeded.

4
Sample Interaction Output
Enter account number (-1 to end) 100 Enter
beginning balance 5394.78 Enter total charges
1000.00 Enter total credits 500.00 Enter credit
limit 5500.00 Account 100 Credit limit
5500.00 Balance 5894.78 Credit Limit
Exceeded. Enter account number (-1 to end) -1
5
Template (1/3)
  • // CPLab3Template\Main.cpp
  • // skj 9/27/2003
  • include ltiostreamgt
  • using stdcout
  • using stdcin
  • using stdendl
  • using stdfixed
  • include ltiomanipgt
  • using stdsetprecision

6
Template (2/3)
  • int main()
  • int accountNumber// customers account number
  • double balance // customers balance
  • double charges // charges on the account
  • double credits // credits to the account
  • double limit // credit limit on the account
  • cout ltlt "Enter account number (-1 to end) "
  • ltlt fixed
  • / write code to read the customer's account
  • number here /
  • / begin loop here /
  • / prompt and read the customer's balance here
  • /
  • / prompt and read the customer's charges here
  • /

7
Template (3/3)
  • / prompt and read the customer's credits here
  • /
  • / prompt and read the customer's credit limit
  • here /
  • / calculate the new customer's balance here
  • /
  • / determine if customer's credit limit is
    exceeded /
  • / if customer's limit is exceeded print
  • message /
  • cout ltlt "\nEnter account number (-1 to end) "
  • / write code to read the customer's account
  • number here /
  • // end while loop
  • cout ltlt endl // ensure all output is displayed
  • return 0
  • // end main

8
Follow-Up Activities
  • Why is it necessary to ask the user to input the
    first account number before you begin the while
    loop? What problems could occur if the user were
    asked for an account number only inside the while
    loop?
Write a Comment
User Comments (0)
About PowerShow.com