Nested structs


#include<iostream>
using namespace std;
#include<string>
#include<iomanip>//included for using setw(10) function

int main(){
struct codes{
int isbn;
string description;
};
struct abc{//structure template
struct codes handle[2];
string author;
string book;
float price;
};
  
struct abc libry[2]; // declare libry variable that will contain 2 records
int count=0;
while(count<2){

cout<<"book's name = ";
cin>>libry[count].book;
cout<<endl<<" authors name = ";
cin>>(libry[count].author);
cout<<endl<<" price = ";
cin>>libry[count].price;


cout<<endl<<"now enter isbn of the book in integer "<<endl;
cin>>libry[count].handle[count].isbn;
    cout<<endl<<"decription about book =";
cin>>libry[count].handle[count].description;
cout<<endl<<endl;
count++;
}

cout<<"now printing whole set"<<endl;

cout<<"bookno"<<"  bookname "<<"  author"<<"  "<<"price"<<setw(5)<<"isbn"<<"  "<<"description"<<endl<<endl;

for(int x=0;x<2;x++){
cout<<x<<setw(5)<<libry[x].book<<setw(5)<<libry[x].author<<setw(5)<<libry[x].price<<setw(5)<<libry[x].handle[x].isbn<<setw(5)<<libry[x].handle[x].description<<endl<<endl;


}
}




Previous
Next Post »

Comments:

Disqus Shortname