第五章编程题:
(8)
#include <iostream>
#include <cstring>
using namespace std ;
const int ArraySize = 20 ;
int main()
{
char vocabulary[ArraySize] = {0} ;
int i = 0 ;
cout << "Enter words (to stop, type the word done) : \n" ;
do
{
cin >> vocabulary ;
i ++ ;
} while (strcmp(vocabulary, "done")) ;
i-- ;
cout << "You entered a total of " << i << " words.\n" ;
}
(9)
#include <iostream>
#include <string>
using namespace std ;
int main()
{
string vocabulary ;
int i = 0 ;
cout << "Enter words (to stop, type the word done) :\n" ;
do
{
cin >> vocabulary ;
i ++ ;
} while (vocabulary != "done") ;
i --;
cout << "You entered a total of " << i << " words.\n" ;
}
(10)
#include <iostream>
using namespace std ;
int main()
{
int n ;
cout << "Enter number of rows: " ;
cin >> n ;
for (int i=1; i<=n; i++)
{
for (int j=0; j<(n-i); j++) cout << "." ;
for (int j=0; j<i; j++) cout << "*" ;
cout << endl ;
}
return 0 ;
}
这里要注意,计算机的输入队列和输出队列是分开的。