Hello I have an assignment that I pretty much finished heres some of the output is as follows:
Property Type: RNT
Cost: 1500 dollors
Contains: 2 bedrooms
Days On Market: 20 days
Address: 560 Rumproast road
Converting RNT into a RNT..........
ERROR this property is alreay a rental
I want it to number the property type. for example I want it to say "property type 1: RNT, property type 2: RNT. ect.
I cant figure out how to do that without it displaying a garbage number. Heres my source code:
Code:
#include <iostream>
#include <string>
#include <sstream>
#define DATA 10
class properties
{
private:
//char *p_pointer[10];
char type[DATA];
//char RNT[10];
int price;
int bedrooms;
int days_on_market;
char address[50];
public:
properties() {}
properties(char typ[], int pri, int bedrm, int days_on_m, char addr[]);
char* get_type();
char* get_address();
int get_price();
int get_days_on_market();
void convert_to_rental();
void print_listing();
void set_property(char typ[], int pri, int bedrm, int days_on_m,char addr[]);
};
//-------------------------Main()-------------------------------------------
int main()
{
using std::cin;
using std::cout;
using std::endl;
properties prop1("RNT", 1500, 2, 20, "560 Rumproast road");
properties prop2("CND", 2000, 4, 60, "203 lumix vile");
prop1.print_listing();
prop1.convert_to_rental();
prop2.print_listing();
prop2.convert_to_rental();
cin.get();
return 0;
}
//----------- Method definitions of class "properties"--------------
properties::properties(char typ[], int pri, int bedrm,int days_on_m, char addr[])
{
strcpy(type, typ);
price= pri;
bedrooms = bedrm;
days_on_market = days_on_m;
strcpy(address, addr);
}
int properties::get_price()
{
return price;
}
char* properties::get_type()
{
return type;
}
char* properties::get_address()
{
return address;
}
void properties::convert_to_rental()
{
using std::cout;
using std::endl;
cout<<"Converting"<<" "<<type<<" "<<"into a rental......"<<endl;
if (strcmp(type, "RNT") == 0)
{
cout<<"ERROR this property is already a rental"<<endl<<endl;
return;
}
if (strcmp(type, "RNT") != 0)
{
price /= 300;
days_on_market = 1;
strcpy(type, "RNT");
}
cout<<"This property is now a:"<<" " <<type<<endl;
cout<<"Cost:"<<" "<<price<<" "<<"dollors"<<endl;
cout<<"Contains:"<<" "<<bedrooms<<" "<<"bedrooms"<<endl;
cout<<"Days On Market:"<<" "<<days_on_market<<" "<<"days"<<endl;
cout<<"Address:"<<" "<<address<<endl<<endl;
}
int properties::get_days_on_market()
{
return days_on_market;
}
void properties::print_listing()
{
using std::endl;
using std::cout;
cout<<"Property Type:"<<" " <<type<<endl;
cout<<"Cost:"<<" "<<price<<" "<<"dollors"<<endl;
cout<<"Contains:"<<" "<<bedrooms<<" "<<"bedrooms"<<endl;
cout<<"Days On Market:"<<" "<<days_on_market<<" "<<"days"<<endl;
cout<<"Address:"<<" "<<address<<endl<<endl;
}
void properties::set_property(char typ[], int pri, int bedrm, int days_on_m, char addr[])
{
strcpy(type, typ);
price= pri;
bedrooms = bedrm;
days_on_market = days_on_m;
strcpy(address, addr);
}