0

Hey guys,

I'm working on my final project for first semester of Freshmen year and I have a favor to ask of you guys. This project is very important for the final grade, so I'd love to know if I've made any errors so far? The program works, but I mean will I see any errors down the road based on my coding?

#include <iostream>
#include <string>
using namespace std;

class Vendor
{
    private:
            string name;
            int price;
            int quantity;
            int location;
            char letter;
            int start_quantity;

     public:
            /*Vendor();
            Vendor(string,int,int,int,int);
            ~Vendor();
            void vendItem();*/
            int getQuantity(int);
            string* getName();
            int* getPrice();
            char getAlphaLocation(char);
            int getLocation(int);
            /*int getstartquantity();*/
};

char Vendor::getAlphaLocation(char letter)
{
    switch(letter)
    {
                  case 'A': case 'a':
                                     return letter;
                  case 'B': case 'b':
                                     return letter;
                  case 'C': case 'c':
                                     return letter;
                  case 'D': case 'd':
                                     return letter;
    }
    
}

int Vendor::getLocation(int location)
{
    switch(location)
    {
                  case 1:
                                     return location;
                  case 2:
                                     return location;
                  case 3:
                                     return location;
                  case 4:
                                     return location;
    }
}

int* Vendor::getPrice()
{
    int *price = new int[12];
    price[0] = 25;
    price[1] = 25;
    price[2] = 25;
    price[3] = 25;
    price[4] = 25;
    price[5] = 25;
    price[6] = 25;
    price[7] = 25;
    price[8] = 25;
    price[9] = 25;
    price[10] = 25;
    price[11] = 25;
    
    return price; 
    
}

int Vendor::getQuantity(int quantity)
{
    return quantity;
}

string* Vendor::getName()
{
    //start here
    string *name = new string[12];
    name[0] = "A1. Mars";
    name[1] = "A2. Snickers";
    name[2] = "A3. Twix";
    name[3] = "B1. Kit-Kat";
    name[4] = "B2. Peanut";
    name[5] = "B3. Oreos";
    name[6] = "C1. Reeses's...";
    name[7] = "C2. Hershey's";
    name[8] = "C3. 3 Muske...";
    name[9] = "D1. Ferrero";
    name[10] = "D2. Butterf...";
    name[11] = "D3. Baby Ruth";  
    
    return name;
}

int main()
{
    Vendor user;
    int quantity;
    string* name = user.getName();
    int* price = user.getPrice();
    int location;
    char letter;
    
    for(int i = 0; i < 12; i++)
    {
            cout << name[i] << "\t\t" << price[i] << endl;
    }
    
    cout << "Please enter letter of desired item: ";
    cin >> letter;
    while(letter != 'A' && letter != 'B' && letter != 'C' && letter != 'D' && letter != 'a' && letter != 'b' && letter != 'c' && letter != 'd')
    {
     cout << "Please enter the correct letter: ";
     cin >> letter;
     continue;
    }
    
    cout << "You chose letter " << (char)toupper(user.getAlphaLocation(letter));
    
    cout << "\nPlease enter number of desired item: ";
    cin >> location;
    cout << "You chose number " << user.getLocation(location);
    
    cout << "\nSelect amount: ";
    cin >> quantity;
    cout << "You selected " << user.getQuantity(quantity);
    
    getchar();
    getchar();
    return 0;
}
1
Contributor
1
Reply
4
Views
7 Years
Discussion Span
Last Post by godsgift2dagame
0

Hey 2nd poster, I don't know if you're allowed to ask for help in someone else's topic. Also, I doubt anyone help's you if you don't put your code between CODE tags.

Edited by happygeek: fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.