里面有很多关于编程的实用例子

源代码在线查看: gradebook.cpp

软件大小: 583 K
上传用户: zhouqiaks
关键词: 编程
下载地址: 免注册下载 普通下载 VIP

相关代码

				// Fig. 4.7: GradeBook.cpp
				// Member-function definitions for class GradeBook that solves the 
				// class average program with counter-controlled repetition.
				#include 
				using std::cout;
				using std::cin;
				using std::endl;
				
				#include "GradeBook.h" // include definition of class GradeBook
				
				// constructor initializes courseName with string supplied as argument
				GradeBook::GradeBook( string name )
				{
				   setCourseName( name ); // validate and store courseName
				} // end GradeBook constructor
				
				// function to set the course name;
				// ensures that the course name has at most 25 characters
				void GradeBook::setCourseName( string name )
				{
				   if ( name.length() 				      courseName = name; // store the course name in the object
				   else // if name is longer than 25 characters
				   { // set courseName to first 25 characters of parameter name
				      courseName = name.substr( 0, 25 ); // select first 25 characters
				      cout 				         				   } // end if...else
				} // end function setCourseName
				
				// function to retrieve the course name
				string GradeBook::getCourseName()
				{
				   return courseName;
				} // end function getCourseName
				
				// display a welcome message to the GradeBook user
				void GradeBook::displayMessage()
				{
				   cout 				      				} // end function displayMessage
				
				// determine class average based on 10 grades entered by user
				void GradeBook::determineClassAverage()
				{
				   int total; // sum of grades entered by user
				   int gradeCounter; // number of the grade to be entered next
				   int grade; // grade value entered by user
				   int average; // average of grades
				
				   // initialization phase
				   total = 0; // initialize total
				   gradeCounter = 1; // initialize loop counter
				
				   // processing phase
				   while ( gradeCounter 				   {
				      cout 				      cin >> grade; // input next grade
				      total = total + grade; // add grade to total
				      gradeCounter = gradeCounter + 1; // increment counter by 1
				   } // end while
				
				   // termination phase
				   average = total / 10; // integer division yields integer result
				
				   // display total and average of grades
				   cout 				   cout 				} // end function determineClassAverage
				
				
				
				/**************************************************************************
				 * (C) Copyright 1992-2009 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.                     *
				 **************************************************************************/
							

相关资源