1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
const int NUM_MONKEYS = 3;
const int NUM_DAYS = 7;
void display(string [], int, double [][NUM_DAYS], int);
int main(){
string names [NUM_MONKEYS] = {"none","none","none"};
double food [NUM_MONKEYS][NUM_DAYS] = {{0,0,0,0,0,0,0,},{0,0,0,0,0,0,0},{0,0,0,0,0,0,0}};
for (int i = 0; i<NUM_MONKEYS;i++){ //function 1
string name;
cout<<"Please enter the name of the monkey #"<<i+1<<endl;
cin>>name;
names[i] = name;
}
for (int row = 0; row<NUM_MONKEYS; row++){ //function 2
for (int colm = 0; colm<NUM_DAYS; colm++){
cout<<"Monkey #"<<(row+1);
cout<<", Day #"<<(colm+1)<<" ";
cin>>food[row][colm];
}
cout<<endl;
}
display(names, NUM_MONKEYS,food,NUM_MONKEYS);
}
void display(string names[],int size,double numbers[][NUM_DAYS],int rows){
cout << "Names" << setw(6) << "Day1" << setw(6) << "Day2" << setw(6) << "Day3" << endl;
for (int i = 0; i<size;i++){
cout<<names[i] << setw(10);
// for (int x = i; x < rows; ++x)
// {
for (int y = 0; y < NUM_DAYS; ++y)
{
cout<<setw(8)<<numbers[i][y];
}
std::cout << "\n";
//}
}
}
|