Advertisement
skb50bd

Mid I, Album

Jun 10th, 2015
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.51 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. struct albuminfo{
  8.     int id, release_year;
  9.     string title;
  10.     double price;
  11. };
  12.  
  13. struct Album{
  14.     albuminfo A;
  15.     int copies;
  16.     double totalmoney;
  17. };
  18.  
  19. void readData(Album &X);
  20. void updateData(Album &X, int cp);
  21. void printCategories();
  22. void showData(Album &X);
  23. void findAlbum(Album *A, int na, int id, int cp);
  24.  
  25.  
  26. int main(){
  27.  
  28.     cout << "Welcome to Arnob & Friends" << endl;
  29.     cout << "Phase I : Albums Registration" << endl;
  30.  
  31.     int na, i, id, cp;
  32.     double grandTotal = 0.00;
  33.  
  34.     cout << "Enter number of albums: ";
  35.     cin >> na;
  36.  
  37.     Album A[na];
  38.  
  39.     for(i = 0; i < na; i++){
  40.         cout << "Enter info for album " << i + 1 << ": ";
  41.         readData(A[i]);
  42.     }
  43.  
  44.     cout << "Phase II : Album Sales" << endl;
  45.  
  46.     do{
  47.         cout << "Enter album id and number of copies: ";
  48.         cin >> id >> cp;
  49.  
  50.         findAlbum(&A[0], na, id, cp);
  51.     }
  52.     while(id != 0 && cp != 0);
  53.  
  54.     cout << "Phase III : Sales Information" << endl;
  55.  
  56.     printCategories();
  57.  
  58.     for(i = 0; i < na; i++)
  59.         showData(A[i]);
  60.  
  61.     for(i = 0; i < 46; i++)
  62.         cout << "-";
  63.  
  64.     for(i = 0; i < na; i++)
  65.         grandTotal += A[i].totalmoney;
  66.  
  67.     cout.setf (ios :: fixed);
  68.     cout << endl << left << setw(34) << "GRAND TOTAL" << right << setw(11) << setprecision(1) << grandTotal << endl;
  69.  
  70.     cout << "Thank You. Have a good day!" << endl;
  71.  
  72.     return 0;
  73. }
  74.  
  75.  
  76.  
  77. void readData(Album &X){
  78.  
  79.     cin >> X.A.id >> X.A.title >> X.A.price >> X.A.release_year;
  80.     X.copies = 0;
  81.     X.totalmoney = 0.00;
  82.     return;
  83. }
  84.  
  85.  
  86. void findAlbum(Album *A, int na, int id, int cp){
  87.     int i;
  88.     for(i = 0; i < na; i++)
  89.             if(id == A[i].A.id){
  90.                 updateData(A[i], cp);
  91.                 break;
  92.             }
  93.     if(i == na && id != 0 && cp != 0)
  94.         cout << "SORRY, ALBUM NOT AVAILABLE!" << endl;
  95. }
  96.  
  97.  
  98. void updateData(Album &X, int cp){
  99.  
  100.     X.copies += cp;
  101.     X.totalmoney += (cp * X.A.price);
  102.     return;
  103. }
  104.  
  105.  
  106. void printCategories(){
  107.  
  108.     cout << right << setw(3) << "ID" << " " << left << setw(14) << "NAME" << right << setw(13) << "NUMBERS SOLD" << right << setw(14) << "TOTAL AMOUNT" << endl;
  109.     return;
  110. }
  111.  
  112.  
  113. void showData(Album &X){
  114.  
  115.     cout.setf (ios :: fixed);
  116.  
  117.     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;
  118.  
  119.     return;
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement