C++ pointers and lists in classes | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

C++ pointers and lists in classes

I would really appreciate it if someone can help me with my homework I already did 80% of it i reached a point where he asked about making lists which i am terribly bad at and i would appreciate it if someone can give me the code for the following questions:( i provided the code so far below) 8) Define a class for a shopping cart with name ShoppingCart. This class shall have following members: • a private pointer attribute with name articles to the head of a list of articles in the shopping cart of class InCart • three private real valued attributes with names minFressShipping for which purchase value free shipping is offered, sumNetPrice for the total net price sum of all articles in the shopping cart and sumGrossPrice for the total gross price sum. • a public standard constructor initialising an empty shopping cart with both sum values 0 EUR and the purchase value for free shipping with1000 EUR • a public destructor outputting "~ShoppingCart()" and afterwards deleting each article in the shopping cart starting with an output "delete article: " such that no memory leak will exist. https://code.sololearn.com/c3KjLhtmoxE1/?ref=app

9th Feb 2020, 9:43 PM
Mohamad Moussa
Mohamad Moussa - avatar
13 Answers
+ 7
I really think this is fair game. You did quite some work, and now you are stuck, so you ask for help, which is perfectly fine. I think it's just the wording "i would appreciate it if someone can give me the code for..." that might give the wrong impression. We usually encourage not to ask for code, but for advise on how to accomplish a certain task. From my experience, it's not unusual that people provide a sample code then for you for better understanding anyway. Well, now, off to the point. First of all, your "InCart" class definition has some errors you should fix, for example "this" is a pointer and therefore is used with the arrow operator ->. And second, I don't quite understand the relationship between "InCart" and "ShoppingCart", like which class is resposible for what, where the list is handled and so on. E.g. it sounds like the pointer should point into "InCart", which doesn't make a lot of sense to me. Some more detail here would be great so we can provide meaningful advise.
9th Feb 2020, 10:49 PM
Shadow
Shadow - avatar
+ 6
Fixed compile errors. Marked all changes. Added initial requests as specified. Your request is perfectly acceptable within the rules for Q&A. Shadow's wording would make it better. Pedro H.J was taking the rules a little too far. We require proof of effort on your part before providing help. https://code.sololearn.com/chODjpw1HVj3
10th Feb 2020, 12:29 AM
John Wells
John Wells - avatar
+ 5
Quoted from SoloLearn blog: "If you post your homework with the aim of having others to do it for you ..." This refers to the types of posts where someone describes a homework task, with no attempted effort given, and *usually* end up with the typical "can you write it" blah blah blah ... clichè. But I see you have given it a try Mohammad Moussa, so ... may you find your solution, with or without help from the community 👌 Even for a case where no code was provided, there should still be some considerations given. If and when possible, try to see whether they were really clueless, or were looking for easy way out. For example, it may signal a good intention, when the OP tries something (after being given some hints). But when the OP asks for complete code (after being given some hints), then it might not be a good signal, at all. The latter clearly shows a reluctance for trying from the poster's side. (Edited)
9th Feb 2020, 10:22 PM
Ipang
+ 4
Don't give up you can do anything.
9th Feb 2020, 9:57 PM
Pedro H.J
Pedro H.J - avatar
+ 4
Thank you very much for confirmation, John Wells. Mohamad Moussa I created a little demo for the list additional to what already has been provided by John, in case you want to have a look: https://code.sololearn.com/cn0c6h6i7bz9/?ref=app Usually, a recurring theme you will find in linked lists is pointer traversal, meaning you have a pointer which you let iterate over the list by advancing it through the "next" pointer in the class type the list stores. This method is used for almost everything from adding a new object at the back to printing the contents of the list and kind of the "key" to a functioning list. If you need furter help with your assignment or understanding of lists in general, feel free to ask again.
10th Feb 2020, 12:49 AM
Shadow
Shadow - avatar
9th Feb 2020, 9:50 PM
Pedro H.J
Pedro H.J - avatar
+ 2
I'm sorry John Wells Mohamad Moussa Just keep coding
10th Feb 2020, 12:37 AM
Pedro H.J
Pedro H.J - avatar
+ 1
it says that i can ask for hints which i would be grateful for and sorry i didnt realize i cant fo that
9th Feb 2020, 9:51 PM
Mohamad Moussa
Mohamad Moussa - avatar
+ 1
thanks thats really supportive 😄
9th Feb 2020, 9:58 PM
Mohamad Moussa
Mohamad Moussa - avatar
+ 1
true i wouldnt ask for help if i didnt reach a dead end
9th Feb 2020, 10:24 PM
Mohamad Moussa
Mohamad Moussa - avatar
+ 1
that was incredibly helpful ty for your support , and the list shall be handled in the shoppingcart in a later method i will provide the complete question to understand the general idea
9th Feb 2020, 11:02 PM
Mohamad Moussa
Mohamad Moussa - avatar
0
• a public method with name set_minFreeShipping with one parameter assigning its value to the same named attribute. • a public method with name add_article with an amount and a pointer to an article as parameters, adding a new object InCart on heap to the shopping cart and actualising the two sum variables of the class appropriately. • a virtual public method with name print without parameters writing a shopping onto the standard output stream cart formatted as given in the examples at the bottom. Especially the net price sum, the tax (difference gross minus net total sum) and the gross price sum shall be outputted at the end of the shopping cart. Take care to also regard the (may be) shipping cost output of 5.90 EUR (see example at the bottom)!
9th Feb 2020, 11:02 PM
Mohamad Moussa
Mohamad Moussa - avatar
0
this is the rest if the question
9th Feb 2020, 11:03 PM
Mohamad Moussa
Mohamad Moussa - avatar