📄 collegeapplications.cpp
字号:
// Exercise 21.11: CollegeApplications.cpp
// This application inputs standardized test scores and GPA's for a
// class from the user and uses a function template to display the
// class averages for both of the values.
#include <iostream> // required to perform C++ stream I/O
#include <iomanip> // required for parameterized stream manipulators
using namespace std; // for accessing C++ Standard Library members
// function main begins program execution
int main()
{
int classSize; // size of the class
// prompt the user for and input class size
cout << "\nEnter the number of students in the class: ";
cin >> classSize;
// determine whether the user input a valid value
while ( classSize <= 0 )
{
cout << "\nError: Please enter a positive value" << endl;
// prompt the user for and input class size
cout << "\nEnter the number of students in the class: ";
cin >> classSize;
} // end while
// dynamically allocate memory for the tests array
int *tests = new int[ classSize ];
// dynamically allocate memory for the GPA's array
double *GPAs = new double[ classSize ];
for ( int count = 0; count < classSize; count++ )
{
// prompt the user for and input the standardized test scores
cout << "\nEnter student #" << count + 1 << "'s standardized "
<< "test score (0 - 1600): ";
cin >> tests[ count ];
// determine whether the user entered valid input
while ( tests[ count ] < 0 || tests[ count ] > 1600 )
{
cout << "\nError: Please enter a value between 0 and 1600"
<< endl;
// prompt the user for and input the standardized test score
cout << "\nEnter student #" << count + 1 << "'s "
<< "standardized test score (0 - 1600): ";
cin >> tests[ count ];
} // end while
// prompt the user for and input the student's GPA
cout << "Enter student #" << count + 1 << "'s GPA "
<< "(0.0 - 4.0): ";
cin >> GPAs[ count ];
// determine whether the user entered valid input
while ( GPAs[ count ] < 0.0 || GPAs[ count ] > 4.0 )
{
cout << "\nError: Please enter a value between 0.0 and 4.0"
<< endl;
// prompt the user for and input the student's GPA
cout << "\nEnter student #" << count + 1 << "'s GPA "
<< "(0.0 - 4.0): ";
cin >> GPAs[ count ];
} // end while
} // end for
// calculate and display the standardized test and GPA averages
return 0; // indicate that program ended successfully
} // end function main
/**************************************************************************
* (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 + -