473,395 Members | 2,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Need help on the display total value of all item

Hi, I've this function in a class to update the total value.but when i try to remove the these row highlight in Bold it crash, what should i do????

void display_total_value()

{
double value;
double totalvalue=0;
int r, c;
setcolor (11);
for( r=0; r<row; r++ )

{
for( c=0; c<col; c++ )
{
if(warehouseshelfTVs[r][c] == 0) // ** check if item on shelf
cout <<"\t"<<warehouseshelf[r][c] << " " << "none\t";
else

value=warehouseshelf[r][c]*warehouseshelfTVs[r][c]->cost;
totalvalue=value + warehouseshelf[r][c];
}
cout << " "<< endl;
}
cout <<"\t"<< "Total value is = $" << totalvalue << endl;
system("PAUSE");
}

below is the whole code
Expand|Select|Wrap|Line Numbers
  1. #include <iostream.h>
  2. #include <iomanip.h>
  3. #include <string.h>
  4. #include <process.h>
  5. #include <cstdlib>
  6. #include <windows.h>
  7.  
  8. #define  row  4
  9. #define  col  5
  10.  
  11. //The function that you'll use to
  12. //set the colour
  13.  
  14. void setcolor(unsigned short color)                 
  15. {                                                   
  16.     HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
  17.     SetConsoleTextAttribute(hcon,color);
  18. }
  19.  
  20. class TV                                                  
  21. public :  // ** made public for now
  22.     int itemno;
  23.     char description[100];    
  24.     char model[100];      
  25.     double cost;
  26.     int quantity;  // ** added
  27.  
  28.     //    this function will prompt user to key in details
  29.  
  30.     void update()
  31.  
  32.     {    setcolor (11);
  33.         cout << " "<< endl;
  34.         cout <<"\t"<< "Enter item no: ";cin >>itemno;
  35.         cout <<"\t"<< "Enter description: ";
  36.         cin.ignore();
  37.         cin.getline( description, 100 );
  38.         cout <<"\t"<<"Enter model: ";
  39.         cin.getline( model, 100 );
  40.         cout <<"\t"<< "Enter cost: $";cin >> cost;
  41.         quantity=0;   // ** initialise
  42.     }
  43.  
  44.     void display_item()
  45.  
  46.     {    setcolor (11);
  47.         cout << " "<< endl;
  48.         cout <<"\t"<< "Item no: " << itemno << endl;
  49.         cout <<"\t"<< "Description of item: " << description << endl;
  50.         cout <<"\t"<< "Model: "<<model<<endl;
  51.         cout <<"\t"<< "Cost of item: $ " << cost << endl;
  52.         cout << " "<< endl;
  53.         system("PAUSE");
  54.     }
  55. };
  56.  
  57. class shelf
  58. {    
  59.     int  warehouseshelf[row][col];  // ** initialise to 0 here
  60.     TV  *warehouseshelfTVs[row][col];// ** added TVs
  61.     double itemcost;
  62.     int itemno;
  63.     int quantity;
  64.     double cost;
  65.  
  66. public:
  67.  
  68.     void initial()
  69.     {    
  70.         int r, c;
  71.         for( r=0; r<row; r++ )
  72.             for( c=0; c<col;c++ )
  73.             { warehouseshelf[r][c] = 0; warehouseshelfTVs[r][c] = (TV *) 0; }
  74.     }
  75.  
  76.     //    this function will update the shelf quantity
  77.  
  78.     void update_shelfs(TV *brand)
  79.  
  80.     {    
  81.         int i, numitems, r , c, quantity;
  82.         setcolor (11);
  83.         cout << " "<< endl;
  84.  
  85.         {
  86.             cout <<"\t"<< "Enter which row to update for item: ";    cin >> r;
  87.  
  88.             cout <<"\t"<< "Enter which column to update for item: "; cin >> c;
  89.  
  90.             cout <<"\t"<< "Enter no of quantity to update for item: ";    cin >> quantity;
  91.  
  92.                     warehouseshelfTVs[r][c]=brand;   // ** added TV to shelf
  93.             warehouseshelf[r][c] = quantity;
  94.         }
  95.         setcolor (12);
  96.         cout <<"\t"<< "Update completed................." << endl;
  97.         setcolor (11);
  98.         system("PAUSE");
  99. }    
  100.  
  101.     void display_shelfs()
  102.  
  103.     {    setcolor (11);
  104.         int r, c;
  105.  
  106.         for( r=0; r<row; r++ )   
  107.  
  108.         {
  109.             for( c=0; c<col; c++ )
  110.             {
  111.              if(warehouseshelfTVs[r][c] == 0)         // ** check if item on shelf
  112.                  cout <<"\t"<<warehouseshelf[r][c] << " " <<  "none\t";                
  113.              else
  114.                 cout <<"\t"<<warehouseshelf[r][c] << " " <<  warehouseshelfTVs[r][c]->itemno<<"\t";             
  115.             }
  116.         cout << " "<< endl;
  117.         }
  118.         system("PAUSE");
  119.     }
  120.  
  121.     void display_total_all_items_stored()
  122.  
  123.     {    setcolor (11);
  124.         int sum  = 0;
  125.         int r, c;
  126.  
  127.         for( r=0; r<row; r++ )
  128.         {    
  129.             for( c=0; c<col; c ++ )
  130.             {
  131.                 sum = sum + warehouseshelf[r][c];            }
  132.         }
  133.         cout <<"\t"<< "Total sum of items is = " << sum << endl;
  134.             system("PAUSE");
  135.     }
  136.  
  137.     void display_total_value()
  138.  
  139.     {    
  140.         double value;
  141.         double totalvalue=0;
  142.         int r, c;
  143.         setcolor (11);
  144.         for( r=0; r<row; r++ )   
  145.  
  146.         {
  147.             for( c=0; c<col; c++ )
  148.             {
  149.              if(warehouseshelfTVs[r][c] == 0)         // ** check if item on shelf
  150.                  cout <<"\t"<<warehouseshelf[r][c] << " " <<  "none\t";                
  151.              else
  152.                 value=warehouseshelf[r][c]*warehouseshelfTVs[r][c]->cost;
  153.                 totalvalue=value + warehouseshelf[r][c];             
  154.             }
  155.         cout << " "<< endl;
  156.         }
  157.  
  158.         cout <<"\t"<< "Total value is = $" << totalvalue << endl;
  159.         system("PAUSE");
  160.   }
  161. };
  162.  
  163. class warehouse
  164. {
  165.  
  166. public:
  167.  
  168.         // function to update address
  169.     char tempaddress[200];
  170.     char *update_address (void)
  171.     {    
  172.         setcolor (11);
  173.         cout <<"\t"<< "Enter address: ";
  174.         cin.getline (tempaddress, 200);
  175.         cout << " "<< endl;
  176.         cout <<"\t"<<"Address for the warehouse is "<<tempaddress <<endl;
  177.         cout << " "<< endl;
  178.         int size = strlen (tempaddress); //** change the string lenght
  179.         char *test = new char[size];    
  180.         //strcpy (test, tempaddress);
  181.         //cout <<"\t"<<strlen (tempaddress);
  182.  
  183.         return test;
  184.                                 delete test;
  185.     }
  186.  
  187.     void display_Address (void)
  188.     {    setcolor (11);
  189.           {cout <<"\t"<<"Update address is "<<tempaddress<<endl;
  190.         cout << " "<< endl;}
  191.         setcolor (14);
  192.     }
  193. };
  194.  
  195.  
  196.     //function to show display menu
  197.  
  198.     void display_menu()
  199.  
  200.     {    
  201.         cout << " "<< endl;
  202.         cout <<"\t"<< "Select option " << endl;
  203.         cout <<"\t"<< "-----------------------" << endl;
  204.         setcolor (11);
  205.         cout <<"\t"<< "1) Update item details " << endl;
  206.         cout <<"\t"<< "2) Display item details " << endl;
  207.         cout <<"\t"<< "3) Update warehouse address" << endl;
  208.         cout <<"\t"<< "4) Display Updated warehouse address" << endl;
  209.         cout <<"\t"<< "5) Add items to the warehouse shelf" << endl;
  210.         cout <<"\t"<< "6) Display warehouse detail" << endl;
  211.         cout <<"\t"<< "7) Find total number of items in warehouse" << endl;
  212.         cout <<"\t"<< "8) Find total value in warehouse" << endl;
  213.         cout <<"\t"<< "9) Exit "<<endl;
  214.         setcolor (14);
  215.         cout <<"\t"<< "-----------------------" << endl;
  216.         cout <<"\t"<< "Enter option: ";    
  217.  
  218.     }
  219.  
  220.     void select_choice()
  221.  
  222.     {    
  223.         cout << " "<< endl;
  224.         cout <<"\t"<<"Select TV  "<<endl;
  225.         cout <<"\t"<< "-----------------------" << endl;
  226.         setcolor (11);
  227.         cout <<"\t"<<"1 for TV1"<<endl;
  228.         cout <<"\t"<<"2 for TV2"<<endl;
  229.         cout <<"\t"<<"3 for TV3"<<endl;
  230.         setcolor (14);
  231.         cout <<"\t"<< "-----------------------" << endl;
  232.         cout <<"\t"<< "Enter Brand using 1-3: ";
  233.     }
  234.  
  235.  
  236.  
  237.  
  238. int main(void)
  239. {    int i;
  240.     int choice;
  241.     char *address;
  242.  
  243.  
  244.     TV    brand[3]; //** tv class 3 object
  245.     shelf s1;
  246.     s1.initial();
  247.     warehouse w1;
  248.  
  249.  
  250.     do
  251.     {    setcolor (14);
  252.         system("cls");
  253.         display_menu();
  254.         cin >> choice;
  255.         cin.ignore();
  256.         switch( choice )
  257.         {    
  258.             case 1:    system("cls");
  259.  
  260.                     {    cout << " "<< endl;
  261.                         cout <<"\t"<<"Update item details" << endl;
  262.                         cout <<"\t"<<"-----------------------"<<endl;
  263.                         select_choice();
  264.  
  265.                         do 
  266.                         {    
  267.                             cin >>i;
  268.  
  269.                             if (i==0||i>3)
  270.                                 {    
  271.                                     cout <<" "<<endl;
  272.                                     setcolor (12);
  273.                                     cout <<"\t"<<"Wrong choice. Pls enter 1-3: ";
  274.                                 }
  275.                             else 
  276.                                 {
  277.                                     brand[i-1].update();
  278.                                 }
  279.                         }
  280.                         while (i==0||i>3);
  281.                     }
  282.  
  283.             break;
  284.  
  285.             case 2:    system("cls");
  286.  
  287.                 {    cout << " "<< endl;
  288.                     cout <<"\t"<<"Display item details" << endl;
  289.                     cout <<"\t"<<"-----------------------"<<endl;
  290.                     select_choice();
  291.  
  292.                 do 
  293.                     {
  294.                         cin >>i;
  295.  
  296.                         if (i==0||i>3)
  297.                             {    
  298.                                 cout <<" "<<endl;
  299.                                 setcolor (12);
  300.                                 cout <<"\t"<<"Wrong choice. Pls enter 1-3: ";
  301.                             }
  302.                         else 
  303.                             {
  304.                                 brand[i-1].display_item();
  305.                             }
  306.                     }
  307.                 while (i==0||i>3);
  308.                 }
  309.  
  310.             break;
  311.  
  312.             case 3:    system("cls");
  313.                 setcolor (14);
  314.                 cout << " "<< endl;
  315.                 cout <<"\t"<<"Update address" << endl;
  316.                 cout <<"\t"<<"-----------------------"<<endl;
  317.                 cout <<" "<<endl;                
  318.                 address = w1.update_address();
  319.                 system("PAUSE");
  320.  
  321.                 break;
  322.  
  323.             case 4:    system("cls");
  324.  
  325.                 cout << " "<< endl;
  326.                 cout <<"\t"<<"Display Updated warehouse address" << endl;
  327.                 cout <<"\t"<<"-----------------------"<<endl;
  328.                 cout <<" "<<endl;                
  329.                 w1.display_Address ();
  330.                 system("PAUSE");
  331.  
  332.                 break;
  333.  
  334.             case 5:    system("cls");
  335.  
  336.                 {    cout << " "<< endl;
  337.                     cout <<"\t"<<"Update Warehouse Shelfs" << endl;
  338.                     cout <<"\t"<<"-----------------------"<<endl;
  339.                     select_choice();
  340.                 do 
  341.                     {
  342.                         cin >>i;
  343.  
  344.                         if (i==0||i>3)
  345.                             {    
  346.                                 cout <<" "<<endl;
  347.                                 setcolor (12);
  348.                                 cout <<"\t"<<"Wrong choice. Pls enter 1-3: ";
  349.                             }
  350.                         else 
  351.                             {    
  352.                                 cout << " "<< endl;
  353.                                 s1.update_shelfs(&brand[i-1]);  // ** pass in TV item
  354.                             }
  355.                     }
  356.                 while (i==0||i>3);
  357.                 }
  358.  
  359.             break;
  360.  
  361.             case 6:    system("cls");
  362.  
  363.                 {    cout << " "<< endl;
  364.                     cout <<"\t"<<"Display Warehouse Selfs" << endl;
  365.                     cout <<"\t"<<"-----------------------"<<endl;
  366.                             {    
  367.                                 cout << " "<< endl;
  368.                                 s1.display_shelfs();
  369.                             }
  370.  
  371.                 }
  372.  
  373.             break;
  374.  
  375.         case 7:    system("cls");
  376.  
  377.         {    cout << " "<< endl;
  378.             cout <<"\t"<<"Display Total Items" << endl;
  379.             cout <<"\t"<<"-----------------------"<<endl;
  380.  
  381.         {
  382.                                 cout<<" "<<endl;
  383.                                 s1.display_total_all_items_stored();
  384.         }
  385.                 }
  386.  
  387.             break;
  388.  
  389.  
  390.             case 8: system("cls");
  391.  
  392.                 {    cout << " "<< endl;
  393.             cout <<"\t"<<"Display Total Value" << endl;
  394.             cout <<"\t"<<"-----------------------"<<endl;
  395.  
  396.     {
  397.                             cout<<" "<<endl;
  398.                             s1.display_total_value();
  399.             }
  400.  
  401.             }
  402.         break;
  403.  
  404.         case 9: 
  405.         cout <<" "<<endl;
  406.         setcolor (12);
  407.         cout <<"\t"<< "Bye Bye. See you again"<<endl;
  408.         cout<<" "<<endl;
  409.         break;
  410.  
  411.         default:
  412.         cout<<" "<<endl;
  413.         setcolor (12);
  414.         cout <<"\t"<<"Invalid choice.Pls re-enter again"<<endl;
  415.                 system("PAUSE");
  416.         }
  417.     }     while( choice != 9 );
  418.     return 0;
  419. }
  420.  
Thanks
Jan 30 '07 #1
2 2180
horace1
1,510 Expert 1GB
you only need to add to the total value if there is something on the shelf, e.g.
Expand|Select|Wrap|Line Numbers
  1.     void display_total_value()    
  2.     {    
  3.         double value;
  4.         double totalvalue=0;
  5.         int r, c;
  6.         setcolor (11);
  7.         for( r=0; r<row; r++ )   
  8.         {
  9.             for( c=0; c<col; c++ )
  10.             {
  11.                         if(warehouseshelfTVs[r][c] != 0)         // ** check if item on shelf
  12.                                 totalvalue+=warehouseshelf[r][c]*warehouseshelfTVs[r][c]->cost;
  13.             }
  14.         cout << " "<< endl;
  15.         }    
  16.         cout <<"\t"<< "Total value is = $" << totalvalue << endl;
  17.         system("PAUSE");
  18.   }
  19. };
  20.  
Jan 30 '07 #2
Thanks for the help.
you only need to add to the total value if there is something on the shelf, e.g.
Expand|Select|Wrap|Line Numbers
  1.     void display_total_value()    
  2.     {    
  3.         double value;
  4.         double totalvalue=0;
  5.         int r, c;
  6.         setcolor (11);
  7.         for( r=0; r<row; r++ )   
  8.         {
  9.             for( c=0; c<col; c++ )
  10.             {
  11.                         if(warehouseshelfTVs[r][c] != 0)         // ** check if item on shelf
  12.                                 totalvalue+=warehouseshelf[r][c]*warehouseshelfTVs[r][c]->cost;
  13.             }
  14.         cout << " "<< endl;
  15.         }    
  16.         cout <<"\t"<< "Total value is = $" << totalvalue << endl;
  17.         system("PAUSE");
  18.   }
  19. };
  20.  
Jan 31 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: R.Wieser | last post by:
Hello All, I'm trying to get a "Virtual Listbox" to work. I've currently got a form, and used CreateWindowExA to create a ListBox with the LBS_OWNERDRAWFIXED and LBS_NODATA flags on it. I've...
17
by: EkteGjetost | last post by:
This is definitely not the smart thing to do as far as my learning goes, but desperate situations call for desperate measures. The final lab for my introduction to C programming class is due...
0
by: south622 | last post by:
I'm taking a beginning Java course and I'm stuck in week eight of a nine week course. If anyone could help me I would greatly appreciate it. This assignment was due yesterday and each day I go past...
38
by: JenniferT | last post by:
OK, so I'm very new to Java programming and I've been able to squeek by so far, but I'm completely stuck on this assignment. Here is the assignment that is due this week - • Modify the Inventory...
3
sammyboy78
by: sammyboy78 | last post by:
I'm trying to display an array of objects using a GUI. My instructions are that the CD class and it's sublcass don't need to change I just need to modify class CDInventory to include the GUI. I'm not...
6
sammyboy78
by: sammyboy78 | last post by:
I'm trying to display my array of objects in a GUI. How do I get JLabel to refer to the data in my objects? I've read my textbook and some tutorials online I just cannot get this. Plus all the...
2
by: sammiesue | last post by:
Hi, I have form with 2 autosummed textboxes ("total" and "casinototal"). I would like to have a grand total textbox ("grandtotal") get its value from summing "total" and "casinototal", but it...
1
by: twin2003 | last post by:
need help with inventory part 5 here is what I have to do Modify the Inventory Program by adding a button to the GUI that allows the user to move to the first item, the previous item, the next...
2
by: redfog | last post by:
I need help writing some code for this procedure: Inventory – Add to Item Listing menu item (15 points). Application users will use this menu as part of the process of entering inventory...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.