4.19
#include<iostream>
using namespace std;
class book{
public:
book(int qu1)
{
qu=qu1;
price=10*qu1;
}
void show()
{
cout<<qu*price<<'\t';
}
private:
int qu;
int price;
};
int main()
{
book b[5]={book(1),book(2),book(3),book(4),book(5)};
for(int i=0;i<5;i++)
{
b[i].show();
}
cout<<endl;
system("pause");
return 0;
}
4.20
#include<iostream>
using namespace std;
class book{
public:
book(int x)
{
qu=x;
price=10*x;
}
void show()
{
cout<<qu*price<<'\t';
}
private:
int qu;
int price;
};
int main()
{ book *p;
book b[5]={book(1),book(2),book(3),book(4),book(5)};
p=&b[4];
for(int i=0;i<5;i++,p--)
{
p->show();
}
cout<<endl;
system("pause");
return 0;
}