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

📄 salesreport.cpp

📁 C++大学简明教程,解压就行没有密码。希望对大家有用
💻 CPP
字号:
// Exercise 14.12: SalesReport.cpp
// This application calculates and displays one week's sales.
#include <iostream> // required to perform C++ stream I/O
#include <iomanip>  // required for parameterized stream manipulators
#include <string>   // required to access string functions

using namespace std; // for accessing C++ standard library members

const int DAYS_PER_WEEK = 5;

// function prototypes
void displaySales( string [], double [][ DAYS_PER_WEEK ], int );
int displayMenu();

// function main begins program execution
int main()
{
   // define variables
   const int MAXIMUM_ITEMS = 10; // maximum number of items
   const int EXIT_VALUE = 3; // stores the menu option for exit
   const int DISPLAY_VALUE = 2; // stores the menu option for display
   int itemCount = 0; // count of number of items in array
   string itemNames[ MAXIMUM_ITEMS ]; // stores item names
   int response = 1; // stores user's menu selection

   // stores item sales per day
   double dailyItems[ MAXIMUM_ITEMS ][ DAYS_PER_WEEK ] = { 0 };

   // display floating-point values as currency
   cout << fixed << setprecision( 2 );

   response = displayMenu(); // display menu

   // repeat until user chooses to exit
   while ( response != EXIT_VALUE && itemCount < MAXIMUM_ITEMS )
   {
      // validate input
      if ( response < 1 || response > EXIT_VALUE )
      {
         // display an error message
         cout << "Error: Enter a value between 1 and 3." << endl;
      } // end if

      // if user selected to view sales, display the sales
      else if ( response == DISPLAY_VALUE )
      {
         // display itemized sales
         displaySales( itemNames, dailyItems, itemCount );
      } // end else if
      else // otherwise, prompt user for and store input
      {

      } // end else

      response = displayMenu();

   } // end while

   // if 10 or more items
   if ( itemCount == MAXIMUM_ITEMS )
   {
      cout << "Maximum number of items entered. Printing sales..."
           << endl;

      // display itemized sales
      displaySales( itemNames, dailyItems, itemCount );
   } // end if

   return 0; // indicates successful termination

} // end function main

// display menu of options
int displayMenu()
{
   int response; // local variable stores user's response

   // display the menu
   cout << "\nSelect one of the following items: " << endl;
   cout << "1 - Enter sales for a new item" << endl;
   cout << "2 - View sales for all items" << endl;
   cout << "3 - Exit the application" << endl;
   cout << "? ";
   cin >> response; // store the user's response

   return response; // return the response

} // end function displayMenu

// display sales by type and day of week
void displaySales( string itemNames[],
                   double dailyItems[][ DAYS_PER_WEEK ],
                   int itemCount )
{
   // display a header
   cout << left;
   cout << "\n" << setw( 10 ) << "Name" << setw( 10 ) << "Monday"
        << setw( 10 ) << "Tuesday" << setw( 10 ) << "Wednesday"
        << setw( 10 ) << "Thursday" << setw( 10 ) << "Friday"
        << setw( 7 ) << "Total" << endl;

   double weekTotal = 0;  // initialize weekly total
   double salesTotal = 0; // initialize total sales

   // output the total sales
   cout << "\nTotal sales: $" << salesTotal << endl;

} // end function displaySales

/**************************************************************************
 * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and               *
 * Pearson Education, Inc. All Rights Reserved.                           *
 * DISCLAIMER: The authors and publisher of this book have used their     *
 * best efforts in preparing the book. These efforts include the          *
 * development, research, and testing of the theories and programs        *
 * to determine their effectiveness. The authors and publisher make       *
 * no warranty of any kind, expressed or implied, with regard to these    *
 * programs or to the documentation contained in these books. The authors *
 * and publisher shall not be liable in any event for incidental or       *
 * consequential damages in connection with, or arising out of, the       *
 * furnishing, performance, or use of these programs.                     *
 **************************************************************************/

⌨️ 快捷键说明

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