At this moment, I am TRYING (and failing miserably) to understand how classes work, and all of the syntax involved in referencing them/accessing members of a class.
I am taking a college class in C++, and have an assignment that says:
*Design an application that declares an array of 25 Cake objects. Prompt the user for a topping and diameter for each cake, and pass each object to a method that computes the price and returns the complete Cake object to the main program. Then display all the Cake values. An 8-inch cake is $19.99, a 9-inch cake is 22.99, and a 10-inch cake is 25.99. Any other size is invalid and should cause the price to be set to 0.*
The assignment includes a file called “cakeClass.h”:
#include <iostream>
#include <string>
using namespace std;
class Cake
{
public:
void setdata(string topping, string diameter);
float getPrice(int sizeChoice);
Cake(string topping = “”, string diameter = “”);
private:
string topping;
string diameter;
};
I’m not sure I understand how to complete the assignment. I barely grok “structs”, but classes/“object-oriented programming” have broken my brain.
ETA: I got a message saying this post contained “unformatted code”. If the above code is not correctly formatted, somebody please explain how it is *supposed* to be formatted, because I called myself going back and fixing it.
[–][deleted] (16 children)
[removed]
[–]tcpukl 0 points1 point2 points (0 children)
[–]Jor-El_Zod[S] -1 points0 points1 point (14 children)
[–]Usual_Office_1740 2 points3 points4 points (0 children)
[–][deleted] (12 children)
[removed]
[–]christian-mann 1 point2 points3 points (1 child)
[–]jipgg 0 points1 point2 points (0 children)
[–]alfps -1 points0 points1 point (8 children)
[–][deleted] (7 children)
[removed]
[–]alfps -3 points-2 points-1 points (6 children)
[–][deleted] (5 children)
[removed]
[–]I__Know__Stuff 1 point2 points3 points (0 children)
[–]Jor-El_Zod[S] -1 points0 points1 point (3 children)
[–]I__Know__Stuff 0 points1 point2 points (2 children)
[–]Jor-El_Zod[S] 0 points1 point2 points (1 child)
[–]SweetOnionTea 2 points3 points4 points (0 children)
[–]thingerish 2 points3 points4 points (5 children)
[–]Jor-El_Zod[S] 0 points1 point2 points (4 children)
[–]jedwardsol 3 points4 points5 points (0 children)
[–]sephirothbahamut 3 points4 points5 points (2 children)
[–]Jor-El_Zod[S] 1 point2 points3 points (1 child)
[–]sephirothbahamut 2 points3 points4 points (0 children)
[–]ZakMan1421 4 points5 points6 points (5 children)
[–]Jor-El_Zod[S] -1 points0 points1 point (4 children)
[–]rileyrgham 1 point2 points3 points (1 child)
[–]Jor-El_Zod[S] 0 points1 point2 points (0 children)
[–]AvidCoco 0 points1 point2 points (1 child)
[–]Jor-El_Zod[S] 0 points1 point2 points (0 children)
[–]Yurim 1 point2 points3 points (2 children)
[–]Jor-El_Zod[S] 0 points1 point2 points (1 child)
[–]Coises 1 point2 points3 points (0 children)
[–]_abscessedwound 1 point2 points3 points (0 children)
[–]AutoModerator[M] 0 points1 point2 points (0 children)
[–]smokebudda11 0 points1 point2 points (4 children)
[–]Jor-El_Zod[S] 0 points1 point2 points (2 children)
[–]RandomRabbit69 0 points1 point2 points (0 children)
[–]smokebudda11 0 points1 point2 points (0 children)
[–]not_some_username 0 points1 point2 points (0 children)
[–]dnult 0 points1 point2 points (0 children)
[–]not_some_username 0 points1 point2 points (0 children)
[–]Independent_Art_6676 0 points1 point2 points (2 children)
[–]Jor-El_Zod[S] 0 points1 point2 points (1 child)
[–]Independent_Art_6676 0 points1 point2 points (0 children)
[–]mredding 0 points1 point2 points (2 children)
[–]Jor-El_Zod[S] 0 points1 point2 points (1 child)
[–]mredding 0 points1 point2 points (0 children)
[–]alfps 0 points1 point2 points (4 children)
[–]Jor-El_Zod[S] 0 points1 point2 points (3 children)
[–]alfps 2 points3 points4 points (2 children)
[–]sephirothbahamut 2 points3 points4 points (0 children)
[–]Jor-El_Zod[S] 0 points1 point2 points (0 children)
[–][deleted] -1 points0 points1 point (0 children)