Pseudocode, wondering about a certain concept.

Okay, first of all, I am *not* a programmer.

Sure, I grasp the basics, variables and equations and such. I really feel like I get what programming is about now-- solving problems. So, I figured the best way to learn and apply knowledge is to make myself a problem to solve. I am having a problem with a certain concept, I'm not sure what to use in this situation:

Pseudocode for my problem:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Keeping up with a lemonade stand's business and profit.

How do I solve this problem?

1) define prices for each ingredient based on pounds
	a) Two parts: Ingredient and price per pound.
		1) Ingredient: Create "sugar" and "lemon_juice" types?.. basically categorize the variables in 2) 
			under sugar or lemonjuice..? 
		2) price per pound: Create "pound_cost" variable, and then APPLY "sugar" or "lemon_juice" to it:
			ie: "sugar.pound_cost" or "lemon_juice.pound_cost"
			also applicable as "pound_cost.sugar"
2) sum up a total price spent per serving, store in servingCost
	The equation for this is sugar.pound_cost + (lemon_juice.pound_cost / 8)

3) define how much John is selling the lemonade for, store in grossProfit
	(int grossProfit = 2.00)

4) grossProfit - servingCost = netProfit

5) Display output of 
  
   Cost per serving: servingCost
   //Skip a line here
   Selling the lemonade at: grossProfit
   //Skip a line here
   Total profit per cup: netProfit 


How exactly would I go about declaring a "type"? Would I need to use classes for this? If not, what should I use to declare the variable sugar.pound_cost for example?

I'm not asking you to spoon-feed me the code for this (though that'd be helpful, I'd learn from it rather than just copypasting). I just need to know what to go research to make this concept effective.

And yeah I know, I could just declare separate variables for each one, but that wouldn't be stretching my limits would it?

Thanks in advance,
Nous

EDIT: just realized it'd be more code-efficient to flip 1A1 and 1A2 (pound_cost.sugar)
Last edited on
nous wrote:
Would I need to use classes for this?

It would be a good approach. I'd do something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <iostream>
#include <string>
using namespace std;

class Ingredient
{
public:

    enum Type {SUGAR,LEMON_JUICE,WATER};

    Type type;
    unsigned int pounds;

    Ingredient(Type t,unsigned int p):
        type(t),pounds(p){}

    double get_price() const
        {return pounds*prices_per_pound[type];}

    string get_name() const
        {return names[type];}

    friend ostream & operator<<(ostream & os,
        const Ingredient & i)
    {
        os << "name: " << i.get_name() << endl;
        os << "quantity: " << i.pounds << " pound(s)" << endl;
        os << "price per pound: "
            << Ingredient::get_ppp(i.type) << endl;
        os << "price: " << i.get_price() << endl;

        return os;
    }

    static void set_ppp(Type t,double p)
        {prices_per_pound[t]=p;}

    static double get_ppp(Type t)
        {return prices_per_pound[t];}

private:

    static const string names[3];
    static double prices_per_pound[3];
};

const string Ingredient::names[3]=
    {"sugar","lemon juice","water"};

double Ingredient::prices_per_pound[3]=
    {1.25,1.75,1.5};

int main()
{
    Ingredient a(Ingredient::SUGAR,5);

    cout << "ingredient a:\n";
    cout << a << endl;

    cout << "modifying price per pound for sugar..." << endl;
    Ingredient::set_ppp(Ingredient::SUGAR,0.75);

    cout << "\ningredient a:\n";
    cout << a << endl;

    Ingredient b(Ingredient::LEMON_JUICE,10);

    cout << "ingredient b:\n";
    cout << b << endl;

    cout << "modifying price per pound for lemon juice"
        "\nand current ingredient quantity..." << endl;
    Ingredient::set_ppp(Ingredient::LEMON_JUICE,2.25);
    b.pounds+=5;

    cout << "\ningredient b:\n";
    cout << b << endl;

    cout << "ingredient c:\n";
    Ingredient c(Ingredient::WATER,2);
    cout << c << endl;

    cout << "hit enter to quit..." << endl;
    cin.get();
    return 0;
}

EDIT:

Hahaha, don't mind me continuously editing this trying to make it shorter...
I tend to do that with the code I post...

EDIT 2:

Duoas (below) wrote:
Don't forget water...

Ah, right! Ok, fixed. Water ingredient type is now supported.

@nous:

You should thank Duoas for reminding us that. Mind that a successful lemonade stand owner mostly sells water with sugar. Lemon juice is added in traces just for the taste ;)
Last edited on
Don't forget water...
Thank you so very much r0shi :D that'll give me a good base to work from / learn more about classes through. And weird, water WAS in the initial psuedocode o: must've somehow gotten cut off..? Anyway, thank you, I'm marking as solved.
Topic archived. No new replies allowed.