1. The cout statement below outputs a spectrum value and a team
character string. Modify this line using the setw function so that
each spectrum value is output in a field 10 characters wide and each
team string is output in a field 8 characters wide.
#include <iostream.h>
void main()
{
float spectrum[] = { 6.24, 3.87, 5.06, 2.19, 4.38 };
char *team[] = {"Bozo", "Gonzo", "Rollo", "Marco"};
for (int level = 0; level < 4; level++)
{
cout << spectrum[level] << team[level] << endl;
}
}
2. Modify the cout statement below to specify that 2 digits of
precision are to be used when printing spectrum's floating point
values.
#include <iostream.h>
void main()
{
float spectrum[] = { 6.24, 3.87, 5.06, 2.19, 4.38 };
for (int level = 0; level < 5; level++)
{
cout << spectrum[level] << endl;
}
}
3. Write the function that defines the overloaded >> operator for
ZooAnimal objects to input values for the name, cage number, weight
date, and weight (respectively) of the ZooAnimal object parameter.
class ZooAnimal
{
private:
char *name;
int cageNumber;
int weightDate;
int weight;
public:
ZooAnimal (char*, int, int, int); // constructor function
inline ~ZooAnimal () { delete [] name; }; // destructor function
void changeWeight (int pounds);
char* reptName ();
int reptWeight ();
int daysSinceLastWeighed (int today);
friend ostream& operator<< (ostream& stream, ZooAnimal& Z);
friend istream& operator>> (istream& stream, ZooAnimal& Z);
};