Jun 11, 2014 at 5:31pm UTC
Hi when i run my code in code Blocks does not show me the out put?
can anyone help me?
Thanks
Here my car.txt
Type order ARR number kind loaded destination
Car car1 CN 819481 maintenance false NONE
Car car2 SLSF 46871 business true Memphis
Car car3 AOK 156 tender true McAlester
FreightCar car4 MKT 123456 tank false Fort Worth
FreightCar car5 MP 98765 box true Saint Louis
FreightCar car6 SP 567890 flat true Chicago
// Inheritance to create two new classes.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "Car.h"
#include "FreightCar.h"
#include "PassengerCar.h"
#include <fstream>
int main()
{
string line;
ifstream carsFile ("cars.txt");
cout<<"Type ARR number kind loaded destination\n";
if (carsFile.is_open())
{
while (carsFile.good() )
{
getline (carsFile,line);
char* cstr = new char [line.size()+1];
strcpy (cstr, line.c_str());
char* splitter= strtok(cstr,"|");
int count=0;
string Type;
string order;
string ARR;
int number;
string kind;
string loaded;
string destination;
while (splitter != NULL)
{
if(count==0){
Type=splitter;
}
if(count==1){
order=splitter;
}
if(count==2){
ARR=splitter;
}
if(count==3){
number=atoi(splitter);
}
if(count==4){
kind=splitter;
}
if(count==5){
loaded=splitter;
}
if(count==6){
destination=splitter;
count=-1;
}
splitter = strtok (NULL, "|");
count++;
}
if(strcmp(Type.c_str(),"Car")==0){
Car Cartemp(order,ARR,number,loaded,destination);
Cartemp.setKind(kind);
Cartemp.setUpCar();
}
if(strcmp(Type.c_str(),"FreightCar")==0){
FreightCar FreightCartemp(order,ARR,number,loaded,destination);
FreightCartemp.setKind(kind);
FreightCartemp.setUpCar();
}
if(strcmp(Type.c_str(),"PassengerCar")==0){
PassengerCar PassengerCartemp(order,ARR,number,loaded,destination);
PassengerCartemp.setKind(kind);
PassengerCartemp.setUpCar();
}
}
carsFile.close();//close file
}
else{ cout << "No such file\n\n";}
//delay
system("pause");
return 0;
}
Code;
#include "StdAfx.h"
#include "Car.h"
#include <iomanip>
Car::Car(void)
{
this->Type="";
this->ARR="";
this->number=0;
this->loaded="";
this->destination="";
}
Car::Car(const Car &obj){
*this=obj;
}
Car::~Car(void)
{
}
Car::Car(string newType,string newARR,int newnumber,string newloaded,string newdestination){
this->Type=newType;
this->ARR=newARR;
this->number=newnumber;
this->loaded=newloaded;
this->destination=newdestination;
}
void Car::buildCar(string newType,string newARR,int newnumber,string newloaded,string newdestination){
this->Type=newType;
this->ARR=newARR;
this->number=newnumber;
this->loaded=newloaded;
this->destination=newdestination;
}
void Car::setUpCar(){
cout<<this->Type<<"\t"<<this->ARR<<"\t"<<this->number<<"\t"<<left<<setw(15)<<KIND_ARRAY[this->kind]<<"\t"<<this->loaded<<"\t"<<"\t"<<this->destination<<"\n";
}
void Car::setKind(string kind){
this->kind=other;
if(strcmp(kind.c_str(),"business")==0){
this->kind=business;
}
if(strcmp(kind.c_str(),"maintenance")==0){
this->kind=maintenance;
}
}
#pragma once
#include <iostream>
#include <string>
#include "Kind.h"
using namespace std;
class Car
{
protected:
string Type;
string ARR;
int number;
Kind kind;
string loaded;
string destination;
public:
//default constructor
Car(void);
//a copy constructor
Car(const Car &obj);
//constructor that has five parameters
Car(string newType,string newARR,int newnumber,string newloaded,string newdestination);
~Car(void);
void buildCar(string newType,string newARR,int newnumber,string newloaded,string newdestination);
void setKind(string kind);
void setUpCar();
};
Last edited on Jun 11, 2014 at 5:33pm UTC