We were given two countries, namely Brazil and Argentina. Both had one inventory each with 100 iPods in them. The cost of an iPod in Brazil was 100/unit and in Argentina it was 50/unit. But to get iPods form Argentina, you also had to pay 400/10units. Now they give us some number and we had to find out which purchase would be cheaper.#include<iostream.h>#include<string.h>#include<stdlib.h>#include<conio.h>class country{  public:    int name;    int items,unit;    float cost,price;  public:    country();    void purchase(std::string,int);    void setData(int,int,float,float, int);};country::country(){}void country::setData(int name,int items,float cost,float price,int unit){  name=name;  items=items;  cost=cost;  price=price;  unit=unit;}void country::purchase(std::string a, int b){  float custCost=0;  std::cout<<a;  cout<<item<<name;  if(b<=items)  {    items=items-b;    custCost=cost*b;    cout<<name<<:<<items<<:<< custCost;  }}int main(){  country t[2];  t[0].setData(0,100,100,0,0);  t[1].setData(1,100,50,400,20);  std::string a;  int b,con;  cout<<enter the country;  std::cin>>a;  cout<<enter the items needed;  cin>>b;  if(a==brazil)    con=0;  else con=1;  t[con].purchase(a,b);  getch();  return 0;}It works but I am not totally satisfied with my design as I feel it's too cumbersome. Specifically, if I change the price etc., code changes have to be made.
Inventories of iPods for different countries
c++;homework
You code doesn't seem to meet your specifications, but since you claim it works we'll ignore that.blufox's suggestions are good. Here are a few more:Don't store currency as floats. Wrap it in a money class.You don't seem to use the price or unit fields in your country class, so I'd chuck 'em. If you want to keep them, you have to do something about you parameters list for setData. Try fluent interface:brazil.setName(0).setItems(100).setCost(100.00).setPrice(0.00).setUnits(0);SLVNAHTR (Single Letter Variable Names Are Hard To Read)const int NUMBER_OF_WAYS_MAGIC_NUMBERS_SUCK = 800;const std::string CONSTANTS(are better);There really should be some error checking for your input. boost::lexical_cast is good, or if Boost is not an option, try:template <typename InputType>InputType getValidatedInput(const std::string& prompt=std::string()){    std::cout << prompt;    while (true)    {        std::string input;        std::getline(std::cin, input);        std::istringstream converter(input);        InputType result;        converter >> result;        if (converter.fail())        {            std::cout << Invalid input. Try again: ;            continue;        }        char junk;        converter >> junk;        if (converter.fail())        {            return result;        }        std::cout << Extra character found:  << junk . Try again: ;    }}Also add extra validation to ensure that the country entered is either Brazil or Argentina (and not Alaska). You might want to make a menu, so the user knows their options.Declaring your instance variables public might have been a typo. You want them to be private.