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

📄 第12章1driver.cpp

📁 C++上机课的习题答案
💻 CPP
字号:
// Chapter 12 of C++ How to Program
// Driver for class Table

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

#include <iomanip>

using std::setw;

#include <cassert>

#include <ctime>

#include "table.h"

int main() 
{
   // seed random function
   srand( time( 0 ) );

   Table< int > a ( 4,7 );
   /* write code to create a Table of ints of size ( 4, 7 ); 
      name the Table a */
   Table< int > b( 5, 2 );

   cout << "Uninitialized array \"a\" is: \n";
   a.print(); 
   
   cout << "Uninitialized array \"b\" is: \n";
   b.print();

   // initialize array "a" with random values (0-100)
   for ( int i = 0; i < 4; i++ )

      for ( int j = 0; j < 7; j++ )
         a( i, j ) = rand() % 101;
   
   // initialize array "b" with 'g'
   for ( int t = 0; t < 5; t++ )

      for ( int v = 0; v < 2; v++ )
         b( t, v ) = 'g';

   cout << "\nInitialized array \"a\" is now:\n";
   a.print();
   
   cout << "Initialized array b is now: \n"; 
   b.print();

   cout << "\nEnter values for b (10 of them): \n";
   b.inputValues();
   cout << endl;
   b.print();
   cout << endl;

   // retrieve an element of the array using overloaded operator()
   cout << "The element (2, 1) of array \"a\" is: ";
   /* write code that acesses element 2,1 of "a" */
   cout<<a(2,1)<<endl;

   // change an element of the array using overloaded operator()
   a( 2, 1 ) = -1;
   cout << "Changed element (2, 1) to -1: \n"; 
   a.print();

   system("PAUSE");
   return 0;
}

⌨️ 快捷键说明

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