this is my code
Code:
#include <iostream>
using namespace std;
#include "Car.h"
Car::Car(){
int od = 0;
double val = 0.0;
char make = '?';
}
Car::Car(int o, double v, const char* s){
od = o;
val = v;
strcpy(make,s);
}
Car::~Car(){
}
void Car::set(int o, double v, const char* s){
if(o >=0 && o < 999999){
if(v >= 499.99){
od = o;
val = v;
strcpy(make,s);
}
}
else {
int od = 0;
double val = 0.0;
char make = '?';
}
}
int Car::valid() const{
int ret = 0;
if(od >=0 && od < 999999){
if(val >= 499.99){
ret = 1;
}
}
return ret;
}
int Car::valid(const char* s) const{
int ret = 0;
char first[4];
strncpy(first, make, 4);
if(strcmp(first,s) == 0){
ret = 1;
}
if(strcmp(s,make) == 0){
ret = 1;
}
return ret;
}
void Car::display() const{
cout << od << ' ' << val << ' ' << make << endl;
}
int main ( ) {
Car car[5];
car[0].set( 12345, 20000., "2005 Camry");
car[1].set( -45, 20000., "2005 Ford");
car[2].set( 12345, 200., "2005 BMW");
car[3] = Car(456123, 2000., "1995 Mercedes");
car[4] = Car( 1234, 40000., "2005 BMW");
for (int i = 0; i < 5; i++)
if (car[i].valid() != 0)
car[i].display();
for (int i = 0; i < 5; i++)
if (car[i].valid("2005") != 0)
car[i].display();
return 0;
}
this is my header file:
Code:
class Car{
int od;
double val;
char make[30];
public:
Car();
Car(int o, double v, const char* s);
~Car();
void set(int o, double v, const char* s);
int valid() const;
int valid(const char* s) const;
void display() const;
};
i just want to know why i get this as a output:
Code:
12345 20000 2005 Camry
72 1.06072e+292 " << anyone know where this line is here
456123 2000 1995 Mercedes
1234 40000 2005 BMW
12345 20000 2005 Camry
1234 40000 2005 BMW
Other than the second line output it works good