← Archive
article· jaw

A simple C++ program

c++

/*  

   By: JAW

********************************************************************************

This is an interactive program that processes additions, changes and inquiries

to tables containing data on customer credit limits.

******************************************************************************/

//Header Files//

#include <stdio.h>

#include <conio.h>

#include <ctype.h>

//Function Prototypes//

char get_action(void);

int inquiry(float creditlimit[],int custnumber[]);

void add_cust(float creditlimit[], int custnumber[]);

int change(float creditlimit[], int custnumber[]);

int lookup(int number, int custnumber[]);

////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////

int main(void)

{

//Variable Declarations//

char action;

//Hard Coded Tables//

int custnumber[11] = {103,150,241,266,270,399,401,556};

float creditlimit[11] =

{2500.00,3900.00,4000.00,1500.00,2999.99,2000.00,2500.00,1200.00};

//Test Action//

while(toupper(action) != 'X')

{  action = get_action();

   switch(toupper(action))

   {

   case 'I':

inquiry(creditlimit, custnumber);

break;

case 'A':

add_cust(creditlimit, custnumber);

break;

case 'C':

change(creditlimit, custnumber);

break;

   case 'X':

    break;

default:

printf("\nINVALID SELECTION");

 }

}

}

/////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////

//Display Menu And Prompt User//

char get_action()

{

char action;

printf("\nSelect:\n\n");

printf("    I Customer credit limit inquiry\n");

printf("    A Add a new customer\n");

printf("    C Change credit limit\n");

printf("    X Exit\n");

printf("\n  Enter the action code: ");

scanf("%c",&action);

while(getchar()!= '\n');

return(action);

}

///////////////////////////////////////////////////////////////////////////////

//Add New Customer//

void add_cust(float creditlimit[],int custnumber[])

{

//variable declatrations//

int sub;

int number;

float limit;

//loop to find empty space for new customer//

for(sub = 0; sub < 10; ++sub)

  if(custnumber[sub] == 0)

   {

//prompt user for new customer number and limit//

   printf("\nEnter new customer number: ");

   scanf("%i",&number);

   while(getchar()!= '\n');

   printf("Enter new customer's limit: ");

   scanf("%f",&limit);

   while(getchar()!= '\n');

   printf("New customer added to tables.");

//update tables//

   creditlimit[sub] = limit;

   custnumber[sub] = number;

   break;

   }

else

   if(sub >= 9)

   {

//error message if table full//

   printf("\nTable overflow\n");

   }

}

///////////////////////////////////////////////////////////////////////////////

//Customer Credit Limit Inquiry//

int inquiry(float creditlimit[],int custnumber[])

{

//variable declarations//

int found, number;

//prompt user for number display credit limit//

printf("\nCustomer credit limit inquiry\n");

printf("Enter customer number:");

scanf("%i",&number);

while(getchar()!= '\n');

found = lookup(number,custnumber);

if(found  != -1)

printf("\nCustomers credit limit is: %.2f",creditlimit[found]);

else

//error message is number not found//

printf("\nCustomer number not foud");

}

///////////////////////////////////////////////////////////////////////////

//Customer Number Lookup//

int lookup(int number, int custnumber[])

{

//variable declarations//

int found = 0;

int sub;

//lookup loop//

for(sub = 0;sub < 10 ; sub++)

{

if(number == custnumber[sub])

{

    found = 1;

    break;

   }

}

//return not found code//

if(!found )

sub = -1;

return(sub);

}

///////////////////////////////////////////////////////////////////////////////

//Customer Credit Limit change//

int change(float creditlimit[], int custnumber[])

{

//variable declarations//

int sub, input;

float newlimit;

//prompt user for cutomer number change if present//

printf("\nCustomer credit limit change\n");

printf("Enter customer number:");

scanf("%i",&input);

sub = lookup(input,custnumber);

if (sub  != -1)

{

   printf("\nEnter new credit limit:");

   scanf("%f",&newlimit);

   while(getchar()!= '\n');

   creditlimit[sub] = newlimit;

   printf("Tables updated");

   }

else

//error message if number not found//

{

   printf("Customer number not found");

   }

}

 

Tags:

Restored from the original jawtech.com (archived copy). Links and downloads from that era may no longer work.