?? page2_20.cpp
字號(hào):
/*
NIIT 《C++ & CGI PROGRAMMING &SCRRIPTING》 Skill Base
P2.20 ◆無(wú)指導(dǎo)練習(xí)◆
Checkup: MrZhou
18:27 2004-09-26
*/
#include <iostream.h>
// Declare the variables to be used by all the functions
int counter = 0;
char name[10][26];
float amount[10];
// Declare the functions
void getCustomer();
void sort();
void dispAscending();
void dispDescending();
void avgAmount();
void nonZero();
int main()
{
int choice = 0;
getCustomer();
sort();
while(choice != 6)
{
cout << endl << "Menu ";
cout << endl << "1. The maximum amount outstanding";
cout << endl << "2. The minimum amount outstanding";
cout << endl << "3. The average amount outstanding";
cout << endl << "4. The number of customers whose amount outstanding is greater than zero";
cout << endl << "5. The amount outstanding in ascending and descending orders";
cout << endl << "6. Exit" << endl << endl;
cout << "Enter choice ";
cin >> choice;
switch(choice)
{
case 1:
cout << endl << amount[9] << endl;
break;
case 2:
cout << endl << amount[0] << endl;
break;
case 3:
avgAmount();
break;
case 4:
nonZero();
break;
case 5:
dispAscending();
dispDescending();
break;
case 6:
continue;
default:
cout << endl << "Please enter 1-6 only !" << endl;
}
}
return 0;
}
void getCustomer()
{
counter = 0;
cout << "Enter the information for 10 customers" << endl;
while(counter < 10)
{
cout << "Enter the name of the customer: ";
cin >> name[counter];
cout << "Enter the amount outstanding for the customer: ";
cin >> amount[counter];
counter++;
}
}
void sort()
{
counter = 0;
float temp;
while(counter < 9)
{
if(amount[counter] > amount[counter + 1])
{
temp = amount[counter];
amount[counter] = amount[counter + 1];
amount[counter + 1] = temp;
counter = 0;
continue;
}
counter++;
}
}
void dispDescending()
{
cout << endl << "Descending Order " << endl;
for(counter = 9; counter >= 0; counter--)
{
cout << amount[counter] << endl;
}
}
void dispAscending()
{
cout << "Ascending Order " << endl;
for(counter = 0; counter < 10; counter++)
{
cout << amount[counter] << endl;
}
}
void avgAmount()
{
float sum;
for(sum = 0.0f, counter = 0; counter < 10; counter++)
{
sum = sum + amount[counter];
}
cout << endl << "The average amount is : " << sum/10 << endl;
}
void nonZero()
{
int countPositive = 0;
for(counter = 0; counter < 10; counter++)
{
if(amount[counter] > 0)
{
countPositive++;
}
}
cout << endl << "The number of customers whose amount outstanding"
<< " is greater than zero :" << countPositive << endl;
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -