473,473 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Object represent a value and add/remove cart

8 New Member
hi, im working on Book Ordering system and i having trouble how to make the system recognize different price values when i add different books into it, also how to make the system to be able to add/remove cart?
Sep 25 '13 #1
12 1661
Nepomuk
3,112 Recognized Expert Specialist
Hi ryukku1111 and welcome to bytes.com!

The basic answer is: This depends on what you have so far. How do you represent a book? How to you represent an order? How are price values and books connected? And what is your implementation of the cart?

If you can provide more information I'm sure we'll be able to help you.
Sep 25 '13 #2
ryukku1111
8 New Member
i intended to make a list of books to buy like this:

1 C++ for dummies RM250
2 Creativity & Innovation RM200
3 Introduction to Java RM200

and then users can select the books by input the number of the books they chosen, and then from the book selected the system will ask either more selection into or remove the cart or check out, if wanna check, the system will automatically calculate the total price need to pay from the numbers they selected, its like having price tag on the numbers
Sep 25 '13 #3
Nepomuk
3,112 Recognized Expert Specialist
Sounds good so far, but I'm guessing you haven't written any code yet? If so, here are two ideas that will hopefully get you started:
  • A book can be represented as a set of structured values including a name and a price. Do you know of any language elements in C/C++ that would allow you to represent such structures?
  • The available books and the cart are both collections of books. There are several ways to represent collections in C/C++. Which ones do you know? Which of those would be best suited?
Sep 25 '13 #4
ryukku1111
8 New Member
im guessing array for the list of books? i mean i show out the list of books using using "cout" first then write out some code like 1 = RM250, 2 = RM200 then "total = ???" and the cart part i think a= add cart b= remove cart c= reset d= check out, im still a amateur for C++



my coding so far:
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     string c;
  8.     int booknum;
  9.     cout << "**********Welcome to BOOK ORDERING SYSTEM**************" << ".\n";
  10.     cout << "these are the books available now" << ".\n";
  11.     cout << "1 C++ for dummies RM250" << ".\n";
  12.     cout << "2 Creativity & Innovation RM200" << ".\n";
  13.     cout << "3 Intorduction to Java RM200" << ".\n"; //i will put more books into the list
  14.  
  15.     //this is the part i need help
  16.  
  17.  
  18.     cout << "Total amount need to pay: RM" << booknum * (day * 2) << ".\n"; //display total amount
  19.     cout << "Full report: you are ordering " << booknum << " books so amount need to pay is RM" << booknum<< ".\n"; //display full report
  20.     system ("pause");
  21. }
Sep 25 '13 #5
Nepomuk
3,112 Recognized Expert Specialist
An array is certainly an option, yes. If the elements in that list don't change it's probably even the best option.
As to the cart, you could use an array here too. Alternatively you could use a linked list or a double linked list; that depends on how you want to process the items in the list.

Have you figured out how you want to represent of the book structure?
Sep 25 '13 #6
ryukku1111
8 New Member
u mean like this?

input 1 for C++ for dummies = RM250
input 2 for Creativity & Innovation = RM200
input 3 for Introduction to Java = RM200
Sep 25 '13 #7
Nepomuk
3,112 Recognized Expert Specialist
No, that's not what I mean. I mean that you will probably want to have an array or a list of book objects, right? Each book has a name, a price and some other values. Then you can list all books by going through the list and easily add a new book to the cart or remove it from there. There are ways of structuring data in C/C++ which one can use for such tasks and I would strongly recommend that you use one of them.
Sep 25 '13 #8
ryukku1111
8 New Member
ok i will try to do that, maybe u can show me some code reference?
Sep 25 '13 #9
ryukku1111
8 New Member
do i have to declare a value for every element of the arrays?
Sep 25 '13 #10
ryukku1111
8 New Member
so i declare them right like this?
Expand|Select|Wrap|Line Numbers
  1.  int Cplusplus [1] = {1};
  2.     int creativity [1] = {2};
  3.     int Java [1] = {3};
  4.     int management [1] = {4};
Sep 25 '13 #11
ryukku1111
8 New Member
why all the cin and cout become ambiguous?
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int booknum, n, day;
  7.     double Cplusplus = {10};
  8.     int Creativity ={5};
  9.     int Java = {5};
  10.     int Management = {6};
  11.     Cplusplus, Java, Creativity, Management = n;
  12.  
  13.     cout << "**********Welcome to BOOK ORDERING SYSTEM**************" << ".\n";
  14.     cout << "these are the books available now" << ".\n";
  15.     cout << "input Cplusplus for dummies RM10/day" << ".\n";
  16.     cout << "input Creativity for Creativity & Innovation RM5/day" << ".\n";
  17.     cout << "input Java for Intorduction to Java RM5/day" << ".\n"; //i will put more books into the list
  18.     cout << "input Management for Intoduction to management RM6/day" << ".\n";
  19.     cout << ".\n";
  20.     cout << "cart list";
  21.     cin >> n >> ".\n";
  22.     cout >> 
  23.     //this is the part i need help
  24.  
  25.  
  26.     cout << "Total amount need to pay: RM" << booknum * (day * 2) << ".\n"; //display total amount
  27.     cout << "Full report: you are ordering " << booknum << " books so amount need to pay is RM" << booknum<< ".\n"; //display full report
  28.     system ("pause");
  29. }
Sep 25 '13 #12
Nepomuk
3,112 Recognized Expert Specialist
OK, let's see... You wanted a code example, ok. Well, the structures I was hinting at are called stucts and they are very useful for cases such as this one. Say you want to have a structure representing the clothes you own, then the code may look something like this:
Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<string>
  3.  
  4. using namespace std;
  5.  
  6. typedef struct clothing_item {
  7.     int position;
  8.     string name;
  9.     string type;
  10.     string colour;
  11.     double size;
  12.     int amount;
  13. } Item;
  14.  
  15. int main() {
  16.     Item * items = new Item[4];
  17.  
  18.     items[0].name = "red jacket";
  19.     items[0].type = "jacket";
  20.     items[0].colour = "red";
  21.     items[0].size = 41;
  22.     items[0].amount = 1;
  23.  
  24.     items[1].name = "white shirts";
  25.     items[1].type = "shirt";
  26.     items[1].colour = "white";
  27.     items[1].size = 40.5;
  28.     items[1].amount = 2;
  29.  
  30.     items[2].name = "pairs of blue jeans";
  31.     items[2].type = "trousers";
  32.     items[2].colour = "blue";
  33.     items[2].size = 30;
  34.     items[2].amount = 3;
  35.  
  36.     items[3].name = "pair of black socks";
  37.     items[3].type = "socks";
  38.     items[3].colour = "black";
  39.     items[3].size = 42;
  40.     items[3].amount = 1;
  41.  
  42.     cout << "Here are the items I own:" << endl;
  43.     for(int i = 0; i<4; i++) {
  44.         cout << (i + 1) << ". " << items[i].amount << " " << items[i].name << endl;
  45.     }
  46.  
  47.     cout << "Which one do you want to know more about? ";
  48.     int nr;
  49.     cin >> nr;
  50.     cout << "This item is " << items[nr - 1].colour << endl;
  51.  
  52.     // Just to stop the window from closing
  53.     cin >> nr;
  54. }
Next I'd read in the books you want to add to the cart in a loop. The easiest way to do that is probably to have the user enter the number of an item to add that item to the cart or a 0 if he wants to finish. Then you can add up the prices.
Sep 25 '13 #13

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

Similar topics

2
by: Steven Post | last post by:
Hi all, I've got a situation where I have a given string and I need to find which option in a select object has a value matching this string. I know I could do it by iterating through all of the...
14
by: ago | last post by:
Is it possible to have a default value associated python objects? I.e. to flag an attribute in such a way that the assignment operator for the object returns the default attribute instead of the...
2
by: Aaron | last post by:
I have a data sructure setup and I populate it in a loop like so: y=0 while X: DS.name = "ASDF" DS.ID = 1234 list = DS; y = y + 1
2
by: Leo Muller | last post by:
I tried to simplify my problem. What I want to do is to save a string in a variables, and everytime I click a button, the variable string gets a bit longer by adding the time to it: on the form...
7
by: J055 | last post by:
Hi I'm a little confused by this so would appreciate some advice on ways to deal with the following. When I call the CodeMaker.Update static method for the second time I want the dt parameter to...
3
by: Niyazi | last post by:
Hi all, I have a dataTable that contains nearly 38400 rows. In the dataTable consist of 3 column. column 1 Name: MUHNO column 2 Name: HESNO Column 3 Name: BALANCE Let me give you some...
2
by: RSH | last post by:
I have a situation where I am creating a class (oValue) that contains two properties "Name" and "Value". I am using a thrid party grid control which has a DropDownList Control. The...
15
by: Dave Young | last post by:
I'm trying to replicate the behaviour of the Commerce.Dictionary object that was found in Commerce Server 3.0 By using a hashtable or creating a custom class that implements IDictionary, you...
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,...
1
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
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,...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.