Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string>
- using namespace std;
- struct albuminfo{
- int id, release_year;
- string title;
- double price;
- };
- struct Album{
- albuminfo A;
- int copies;
- double totalmoney;
- };
- void readData(Album &X);
- void updateData(Album &X, int cp);
- void printCategories();
- void showData(Album &X);
- void findAlbum(Album *A, int na, int id, int cp);
- int main(){
- cout << "Welcome to Arnob & Friends" << endl;
- cout << "Phase I : Albums Registration" << endl;
- int na, i, id, cp;
- double grandTotal = 0.00;
- cout << "Enter number of albums: ";
- cin >> na;
- Album A[na];
- for(i = 0; i < na; i++){
- cout << "Enter info for album " << i + 1 << ": ";
- readData(A[i]);
- }
- cout << "Phase II : Album Sales" << endl;
- do{
- cout << "Enter album id and number of copies: ";
- cin >> id >> cp;
- findAlbum(&A[0], na, id, cp);
- }
- while(id != 0 && cp != 0);
- cout << "Phase III : Sales Information" << endl;
- printCategories();
- for(i = 0; i < na; i++)
- showData(A[i]);
- for(i = 0; i < 46; i++)
- cout << "-";
- for(i = 0; i < na; i++)
- grandTotal += A[i].totalmoney;
- cout.setf (ios :: fixed);
- cout << endl << left << setw(34) << "GRAND TOTAL" << right << setw(11) << setprecision(1) << grandTotal << endl;
- cout << "Thank You. Have a good day!" << endl;
- return 0;
- }
- void readData(Album &X){
- cin >> X.A.id >> X.A.title >> X.A.price >> X.A.release_year;
- X.copies = 0;
- X.totalmoney = 0.00;
- return;
- }
- void findAlbum(Album *A, int na, int id, int cp){
- int i;
- for(i = 0; i < na; i++)
- if(id == A[i].A.id){
- updateData(A[i], cp);
- break;
- }
- if(i == na && id != 0 && cp != 0)
- cout << "SORRY, ALBUM NOT AVAILABLE!" << endl;
- }
- void updateData(Album &X, int cp){
- X.copies += cp;
- X.totalmoney += (cp * X.A.price);
- return;
- }
- void printCategories(){
- cout << right << setw(3) << "ID" << " " << left << setw(14) << "NAME" << right << setw(13) << "NUMBERS SOLD" << right << setw(14) << "TOTAL AMOUNT" << endl;
- return;
- }
- void showData(Album &X){
- cout.setf (ios :: fixed);
- cout << right << setw(3) << X.A.id << " " << left << setw(14) << X.A.title << right << setw(13) << X.copies << right << setw(14) << setprecision(1) << X.totalmoney << endl;
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement