Quantcast

Maximum PC

It is currently Thu Oct 30, 2014 5:18 am

All times are UTC - 8 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: C++ Data Structure Problem..
PostPosted: Tue Mar 04, 2008 12:45 pm 
8086
8086

Joined: Tue Mar 04, 2008 12:41 pm
Posts: 2
Location: USA
Can Anyone help me with this homework..
The program should do the following:
(1) Define a new data type, fruit, as a C++ class. The class fruit should include:
• The name of the fruit in an item. Ex: “Appleâ€


Top
  Profile  
 
 Post subject:
PostPosted: Tue Mar 04, 2008 6:29 pm 
Sharptooth
Sharptooth
User avatar

Joined: Thu Sep 20, 2007 5:57 pm
Posts: 386
Quoted from Jan. 8th, 2008

Jipstyle wrote:
We should also point out that we don't do homework here.

We answer specific questions and provide advice and trouble shooting .. that's it. Along with witty dialogue about programming concepts and trivia.


With that in mind, do you have any code that we could help you with? Are you experiencing any specific problems?


Top
  Profile  
 
 Post subject:
PostPosted: Thu Mar 06, 2008 7:47 am 
8086
8086

Joined: Tue Mar 04, 2008 12:41 pm
Posts: 2
Location: USA
i have the header file and the class file, but the main one i dont know how to call them and make that list and choices..
#include<iostream>
using namespace std;
#include "fruit.h"

fruit ::fruit()
{
name="";
price=0.0;
quantity=0.0;
}

fruit ::fruit(string name, double price, double quantity)
{
fruit::name=name;
fruit::price=price;
fruit::quantity=quantity;
}

fruit:: ~fruit(){
}
string fruit::getName()
{
return name;
}
double fruit::getPrice()
{
return price;
}
double fruit::getQuantity()
{
return quantity;
}
void fruit::print()
{
cout<<"\n\nFruit Name :\n";
cout<<name;
cout<<"Price : ";
cout<<price;
cout<<"\nQuantity : "<<quantity<<endl;
}

void fruit ::setName(string name)
{
fruit::name=name;
}

void fruit::setPrice(double price)
{

fruit::price=price;

}

void player::setQuantity(double quantity)
{
fruit::quantity=quantity;
}


#ifndef FRUIT_H
#define FRUIT_H

#include <string>
using namespace std;


class fruit{
public:
fruit();
fruit(string name, double price, double quantity);
~fruit();
string getName();
double getPrice();
double getQuantity();
double getCost();
void setName(string);
void setPrice(double);
void setQuantity(double);
void setAll(string n, double p, double q);
void print();
friend ostream& operator<<(ostream&, const fruit&);
private:
string name;
double price;
double quantity;
};
#endif

#include <iostream>
using namespace std;
#include "FRUIT.H"

string FruitNames[]={"Banana","Apple"};

int main()
{
???????
return 0;
}


Top
  Profile  
 
 Post subject:
PostPosted: Thu Mar 06, 2008 9:12 am 
Java Junkie
Java Junkie
User avatar

Joined: Mon Jun 14, 2004 10:23 am
Posts: 24229
Location: Granite Heaven
Use the [code ] [/code] tags, please .. it makes it easier for us to read.

The first response was correct .. we need specific problems to address. What is it doing that you don't expect? What errors are you seeing during compilation?


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

© 2014 Future US, Inc. All rights reserved.