Help with homework | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

Help with homework

How to make_unique and return a unique_ptr.

27th Apr 2024, 9:08 PM
Kevin
4 Antworten
+ 4
Can you specify the task better please?
28th Apr 2024, 1:39 AM
<YostDev>
<YostDev> - avatar
+ 2
I'm not sure how the data for your shapes are supposed to be, so I just specified the Points belonging to them. The rectangle is not guaranteed to be 90 deg, so it should probably just be a considered as general quadrangle. More complicated constuctors are probably needed, but that is not the focus of this exercise. Anyway, this is how I would do it. It might not be what you're after but perhaps it will give you some ideas. I also added an extra experimental method to generate a random pick of shape from a single method, returning a custom type based on std::variant. https://sololearn.com/compiler-playground/cj4dFB6I0zm0/?ref=app
29th Apr 2024, 2:00 PM
Bob_Li
Bob_Li - avatar
+ 1
It says “Create a class called ShapeFactory. Add 7 static methods: a method for creating a random point, a method for creating a random color, and methods for creating unique pointers for each Shape type (Shape, Line, Rectangle, Triangle, Circle). The methods that create the random Shapes should use make_unique and return a unique_ptr.” I just need an example
28th Apr 2024, 1:47 AM
Kevin
+ 1
Check this link, much better than anything: https://www.w3schools.com/cpp/cpp_class_methods.asp https://sololearn.com/compiler-playground/cD3zCE4Ycut5/?ref=app https://sololearn.com/compiler-playground/cjOqjY34lbmO/?ref=app Why don't you attached your attempts with the code? Do try first this is your problem! Attached your effort, we will solve the rest..
28th Apr 2024, 3:52 AM
`нттp⁴⁰⁶
`нттp⁴⁰⁶ - avatar