473,805 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help on the display total value of all item

8 New Member
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_v alue()

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

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

value=warehouse shelf[r][c]*warehouseshelf TVs[r][c]->cost;
totalvalue=valu e + 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 2201
horace1
1,510 Recognized Expert Top Contributor
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
HarisHohkl
8 New Member
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
7875
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 allso subclassed the window and do see all kinds of WS_??? messages coming by. But now I'm stuck :-\ I've got *no* idea what to do next, and all my searching on the web leads me
17
1974
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 tomorrow. I was on vacation when we went over how to read files, so basically my only resources are the book, the course notes, and the examples. Unfortunately for me, none of them are usefull at all, so pretty much i don't have a clue as to what i...
0
7118
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 the due date 10% of the grade is taken off. I think I'm coming down with the flu and my brain is just not processing this assignment. Here is the assignment: Modify the Inventory program by adding a button to the GUI that allows the user to move...
38
4247
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 Program so the application can handle multiple items. Use an array to store the items. The output should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price of each...
3
4758
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 even sure if the way I've written this is going to work but anyway, I keep getting a compilation error that says: C:\Documents and Settings\Sam\GUICDInventory.java:22: cannot find symbol symbol : constructor JList(CDInventory) location: class...
6
3892
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 examples I've seen are creating the information that will be displayed from scratch, while I have to use my previously created classes and add a GUI to it. I'm trying to do this GUI using JLabels but it won't let me refer to my CD class methods that...
2
5080
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 doesn't seem to be working. Here is my code. Thanks for your help. -sammie <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Nursing Conference 2007 Registration Form</title>
1
2827
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 item, and the last item in the inventory. If the first item is displayed and the user clicks on the Previous button, the last item should display. If the last item is displayed and the user clicks on the Next button, the first item should display. the...
2
1494
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 information. The steps for entering inventory information are: (1) select an existing inventory item from the Select Item ComboBox control, (2) enter the wholesale cost of the item and quantity in stock, (3) click the Inventory menu, Add to Item Listing sub...
0
9718
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10614
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10363
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10369
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10109
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5544
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.