⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 page2_20.cc

📁 C++ interview materials. Very helpful for interview. Including Answer.
💻 CC
字号:
/*
NIIT 《C++ & CGI PROGRAMMING &SCRRIPTING》 Skill Base
P2.20		◆无指导练习◆
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;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -