So I have made a program for schoolwork which is supposed to be a bookshop's stock program. The program ought to have Struct, Stack, Pointer, Array, and a Searching Method. My program already has a struct like this (there are more variables in my actual program)
1 2 3 4 5 6
struct BookInfo
{
int year;
string author;
string publisher;
};
My question is, is there any way I can make a stack of this struct, but with 1 book occupying 1 stack? (stack 1 consists of a BookInfo containing all the variables in it, instead of stack 1 only containing year, stack 2 contains author, etc.)
#include <iostream>
usingnamespace std;
struct BookInfo
{
int price, year, stock;
string title;
string author;
};
void input_book(BookInfo data[]);
int main()
{
BookInfo *data = new BookInfo[10];
input_book();
delete [] data;
return 0;
}
void input_book(BookInfo data[])
{
int iPrice, iYear, iStock;
string iTitle, iAuth;
//Forgot to put the loop here, too busy translating var names from my language lol
cout << " Book title : " ; getline(cin, iTitle);
cout << " Price : " ; cin >> iPrice;
cout << " Author : " ; getline(cin, iAuth);
cout << " Year : " ; cin >> iYear;
cout << " Stock : " ; cin >> iStock;
data[0].title = iTitle; //all the zeroes should be i from the loop
data[0].price= iPrice;
data[0].author= iAuth;
data[0].year= iYear;
data[0].stock= iStock;
}
One more thing, my teacher said we can not use stack header for this project so we can understand more of the actual work behind stacks. She told us to create a 'manual' stack, so here is the example that she gave us:
It's still not clear where the stack fits in. In main you create an array to store the BookInfos what makes sense. BTW you need to pass the array to the input_book function.
Why do you input only 1 book when the array has space for 10 ?