By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,319 Members | 2,115 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,319 IT Pros & Developers. It's quick & easy.

Code running on LINUX?

P: n/a
Hey, I have developed the following code and it is executing well on
windows. But I don't have LINUX installed on my system. I would be
grateful to you guys if you check whether this code is working fine on
linux. I know that C++ is independent of OS, but still check it on g++
compiler.
Thanks a lot in advance.
Anchit

CODE:
#include<iostream>
#include<string>

using namespace std;

int m=0, min, k[10], c;

class parkedcar //class holds data of the car in parking
{
string make;
int model;
string color;
string licnumber;
int minutesparked;
public:
parkedcar()
{
make=" ";
model=0;
licnumber=" ";
color=" ";
minutesparked=0;
}

void setmake(string mk)
{
make=mk;
}

void setmodel(int ml)
{
model=ml;
}

void setcolor(string c)
{
color=c;
}

void setlicnumber(string l)
{
licnumber=l;
}

void setminutesparked(int mnp)
{
minutesparked=mnp;
}

string getmake() const
{
return (make);
}

int getmodel() const
{
return (model);
}

string getcolor() const
{
return (color);
}

string getlicnumber() const
{
return (licnumber);
}

int getminutesparked() const
{
return (minutesparked);
}

void print();
};

void parkedcar::print() //outside class definition
{
cout<<"Car Make :"<<getmake()<<endl;
cout<<"Car Model :"<<getmodel()<<endl;
cout<<"Car License Number :"<<getlicnumber()<<endl;
cout<<"Car Color :"<<getcolor()<<endl;
}
class parkingticket: public parkedcar //class calculates and shows
fine (if any)
{
int fine;
int minutes;
void calfine(); //helper function, calculates fine

public:
void showfine(); //function to show the fine
void getticket (int min) //calls the helper function calfine()
{
minutes=min;
calfine();
cout<<endl;
}
int getfine() const
{
return(fine);
}
};

void parkingticket::calfine() //outside class definition
{
if(minutes/60<=0)
{
fine = 45;
}
else
{
int mn;
mn=minutes - 60;
fine = 45 + 30 + 30*(mn/60);
}
}

void parkingticket::showfine() //outside class definition
{
cout<<" ILLEGAL PARKING"<<endl;
cout<<" Time in violation is "<<minutes/60<<" hours & "<<minutes
%60<<" minutes "<<endl;
cout<<" Fine : Rs. "<<getfine()<<endl;
}
parkingticket tck[10]; //Parking ticket array of objects created

class parkingmeter //This class take carea of number of minutes
purchased
{
int minpurchased;
public:
parkingmeter()
{
minpurchased=0;
}
void setminpurchased(int m)
{
minpurchased=m;
}
int getminpurchased() const
{
return(minpurchased);
}
void print()
{
cout<<"Mins purchased are"<<getminpurchased();
}
};

class policeofficer //Responsible for patrolling and issuing
parkingticket
{ //in case vehicle is illegally parked
string name;
string badgenumber;
parkingticket *ticket; //Pointer of the type parkingticket class
public:
policeofficer()
{
name=" ";
badgenumber=" ";
ticket = NULL;
}
void setname(string n)
{
name=n;
}
void setbadgenumber(string b)
{
badgenumber=b;
}
string getname() const
{
return(name);
}
string getbadgenumber() const
{
return(badgenumber);
}
parkingticket* patrol(parkingticket pc1, parkingmeter pc2) //Patrol
function
{
if ( pc1.getminutesparked() < pc2.getminpurchased() ||
pc1.getminutesparked() == pc2.getminpurchased() )
{
return NULL; //No crimes
}
else //Illegal parking
{
tck[m].getticket(pc1.getminutesparked() - pc2.getminpurchased());

cout<<"--------------------------------------------------------------------------------"<<endl;
tck[m].showfine();
ticket=&tck[m];
return(ticket);
}
}
void print()
{
cout<<"Name: "<<getname()<<endl;
cout<<"Badge Number: "<<getbadgenumber()<<endl;
}
};
void intro()
{
cout<<"******************************************* *************************************"<<endl;
cout<<" THIS IS PARKING TICKET SIMULATOR"<<endl;
cout<<"******************************************* *************************************"<<endl;
}

void choice()
{
cin>>c;
if(c==0)
{
m++;
}
else if(c==1)
{

}
else
{
cout<<"Invalid Entry, try again :"<<endl;
choice();
}
}
int main()
{
system("cls");
int i=0, y;

intro();
cout<<"PARKING RATES ::"<<endl;
cout<<"Parking rate is Rs. 25 for 60 minutes"<<endl;
cout<<endl<<endl;
cout<<"FINE RATES ::"<<endl;
cout<<"In case number of minutes car has been parked exceeds the
number of minutes purchased, then a fine is applied."<<endl;
cout<<"Rs 45 for first hour or part of an hour that the car is
illegally parked and Rs 30 for every additional hour or part of an
hour that the car is illegally parked."<<endl;
cout<<"___________________________________________ _____________________________________"<<endl;

policeofficer officer; //Police Officer object created

string pname, pbadge;
cout<<"OFFICER'S INFORMATION ::"<<endl;
cout<<"Name: ";
cin>>pname;
cout<<"Badge Number: ";
cin>>pbadge;
officer.setname(pname);
officer.setbadgenumber(pbadge);
parkingmeter meter[10]; //Parking meter array of objects created

parkingticket* ticket = NULL;

do //Iteration of statements
{

system("cls");
intro();
cout<<"PARKED CAR'S INFORMATION ::"<<endl; //Officer inputs the data
of the car

string mk;
cout<<"Make :";
cin>>mk;
tck[m].setmake(mk);

int mod;
cout<<"Model :";
cin>>mod;
tck[m].setmodel(mod);

string lic;
cout<<"License number :";
cin>>lic;
y=0;
while(y<=m)
{
if (y!=m)
{
if (lic == tck[y].getlicnumber()) //License number being a
primary key
{

cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<"Car with this License Number already exists"<<endl;
tck[y].print();

cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<"Try re-entering the license number :";
cin>>lic;
}
}
y++;
}
tck[m].setlicnumber(lic);

string col;
cout<<"Color :";
cin>>col;
tck[m].setcolor(col);

int parmin; //The number of minutes a car has been parked
cout<<"Minutes in parking :";
cin>>parmin;
tck[m].setminutesparked(parmin);
int purmin; //The number of minutes purchased
cout<<"Minutes purchased :";
cin>>purmin;
meter[m].setminpurchased(purmin);

system("cls");
intro();

ticket = officer.patrol(tck[m], meter[m]); //The officer patrols
if(ticket==NULL)
{
// Display the ticket information.
tck[m].print();
cout<<endl;
cout<<endl;
cout<<"----------------------"<<endl;
cout<<"| NO CRIMES COMMITTED |"<<endl;
cout<<"----------------------"<<endl;
}
else
{
cout<<endl<<"Non-permitted vehicle ::"<<endl;
ticket->print(); // Display the ticket information.

cout<<"--------------------------------------------------------------------------------"<<endl;
ticket = NULL;
}
k[m] = tck[m].getminutesparked() - meter[m].getminpurchased();
cout<<endl<<endl<<endl<<endl<<endl;

cout<<"___________________________________________ _____________________________________"<<endl;
cout<<"Enter your choice -"<<endl;
cout<<"0 - Patrol another car 1 - View cars patrolled"<<endl;
choice();
}while (c == 0);

system("cls");
intro();
for(i=0;i<=m;i++)
{
cout<<" PARKED CAR "<<i+1<<endl<<endl;
tck[i].print();
cout<<endl<<endl;

if (k[i]>0)
{
tck[i].showfine();

cout<<"--------------------------------------------------------------------------------"<<endl;
}
else
{
cout<<"Vehicle permitted for "<<-k[i]/60<<" hours & "<<-k[i]%60<<"
minutes"<<endl;
}

cout<<"=========================================== ====================================="<<endl;
}
cout<<"Officer responsible for issuing these tickets and
patroling ::"<<endl;
officer.print();
return 0;
}
Jul 22 '08 #1
Share this Question
Share on Google+
14 Replies


P: n/a
an********@gmail.com wrote:

[knip]
Ok, if that is supported by linux, and what about rest of the code? Is
it executing in Linux?
There are several Linux distro's which have Live-cd's. No installation is
required so you have no excuse to not try it yourself.

Jul 22 '08 #2

P: n/a
On Jul 22, 12:29*pm, Gunter Schelfhout <no.m...@please.com.invalid>
wrote:
anchitg...@gmail.com wrote:

[knip]
Ok, if that is supported by linux, and what about rest of the code? Is
it executing in Linux?

There are several Linux distro's which have Live-cd's. No installation is
required so you have no excuse to not try it yourself.
sorry, but i dnt knw about distro. Can you give me internet link where
I can execute it?
Jul 22 '08 #3

P: n/a
an********@gmail.com writes:
Hey, I have developed the following code and it is executing well on
windows. But I don't have LINUX installed on my system. I would be
grateful to you guys if you check whether this code is working fine on
linux. I know that C++ is independent of OS, but still check it on g++
compiler.
Thanks a lot in advance.

First, you could try it on cygwin:
http://www.cygwin.com/ (it's free software)
This installs a "linux-like" environment in MS-Windows.
Then, as Gunter commented, there are linux distributions that requires
zero-installation, with so called "Live-CD": you just boot them and
they won't even write on your hard disk.
http://www.frozentech.com/content/livecd.php
Some of them even work from USB memory keys.
I'd advise you to try Kubuntu.
If you want to perfect your "unix" port, try also FreeBSD.

--
__Pascal Bourguignon__
Jul 22 '08 #4

P: n/a
an********@gmail.com wrote:
On Jul 22, 12:29 pm, Gunter Schelfhout <no.m...@please.com.invalid>
wrote:
>anchitg...@gmail.com wrote:

[knip]
>>Ok, if that is supported by linux, and what about rest of the code? Is
it executing in Linux?
There are several Linux distro's which have Live-cd's. No installation is
required so you have no excuse to not try it yourself.

sorry, but i dnt knw about distro. Can you give me internet link where
I can execute it?
google

--
Ian Collins.
Jul 22 '08 #5

P: n/a
an********@gmail.com wrote:
>
So, which header should I include?
Which one did Chris tell you earlier?

--
Ian Collins.
Jul 22 '08 #6

P: n/a
an********@gmail.com wrote:
On Jul 22, 12:29*pm, Gunter Schelfhout <no.m...@please.com.invalid>
wrote:
>anchitg...@gmail.com wrote:

[knip]
Ok, if that is supported by linux, and what about rest of the code? Is
it executing in Linux?

There are several Linux distro's which have Live-cd's. No installation is
required so you have no excuse to not try it yourself.

sorry, but i dnt knw about distro. Can you give me internet link where
I can execute it?
A very good start about several distro's is distrowatch.com.

OpenSUSE, [K|X]Ubuntu, Mandriva, and others all have free live-cd's which
you can download and try with really no risk at all.

Jul 22 '08 #7

P: n/a
On Jul 22, 2:58*pm, Gunter Schelfhout <no.m...@please.com.invalid>
wrote:
anchitg...@gmail.com wrote:
On Jul 22, 12:29*pm, Gunter Schelfhout <no.m...@please.com.invalid>
wrote:
anchitg...@gmail.com wrote:
[knip]
Ok, if that is supported by linux, and what about rest of the code? Is
it executing in Linux?
There are several Linux distro's which have Live-cd's. No installationis
required so you have no excuse to not try it yourself.
sorry, but i dnt knw about distro. Can you give me internet link where
I can execute it?

A very good start about several distro's is distrowatch.com.

OpenSUSE, [K|X]Ubuntu, Mandriva, and others all have free live-cd's which
you can download and try with really no risk at all.
ok, so #include<cstdlibheader is doing the execution perfectly,
right?
Jul 22 '08 #8

P: n/a
an********@gmail.com wrote:
But I don't have LINUX installed on my system. I would be
grateful to you guys if you check whether this code is working fine on
linux. I know that C++ is independent of OS,
_but still check it on g++ compiler_.
In *this* case, I'd like to advice you to download Dev-C++
(http://prdownloads.sourceforge.net/d....9.2_setup.exe)

and install it to C:\DevCPP ore somewhere else.

Then, start the IDE, go through (Menus)
[File] =[New] =[Project]
=[Console Application]
=Name: "anchitgood"
=Save

It'll provide a new project containing a "main.cpp".
Replace this "Hello World" example there by your
program source an hit:
[Execute] ==[Compile]

Thats it.

It has the Gnu-GCC 3.4.2 (3.4.4 after update) and
it's the *only* Win-32 development environment
(I know of) where you'll be able to install and
use the complete Boost-libraries within 60 seconds.

( goto [Tools] =[Chech for updates/Packages]
=[connect server devpaks.org]
=lookup Boost, click Download/Install )

Regards

M.
Jul 22 '08 #9

P: n/a
On Mon, 21 Jul 2008 20:28:31 -0700, anchitgood wrote:
Hey, I have developed the following code and it is executing well on
windows. But I don't have LINUX installed on my system. I would be
grateful to you guys if you check whether this code is working fine on
linux. I know that C++ is independent of OS, but still check it on g++
compiler.
You might first want to test-compile it on Comeau Online:

http://www.comeaucomputing.com/tryitout/

Comeau has a reputation as one of the most standards-compliant compilers
around, and you may specify an "architecture" to compile your code under.

--
Lionel B
Jul 22 '08 #10

P: n/a
On Jul 22, 5:07*pm, Lionel B <m...@privacy.netwrote:
On Mon, 21 Jul 2008 20:28:31 -0700, anchitgood wrote:
Hey, I have developed the following code and it is executing well on
windows. But I don't have LINUX installed on my system. I would be
grateful to you guys if you check whether this code is working fine on
linux. I know that C++ is independent of OS, but still check it on g++
compiler.

You might first want to test-compile it on Comeau Online:

http://www.comeaucomputing.com/tryitout/

Comeau has a reputation as one of the most standards-compliant compilers
around, and you may specify an "architecture" to compile your code under.

--
Lionel B
yeah, its showing compile succeded on comeau link. Compile succeded on
every red hat platform and also on Linux alpha. So this has done the
job, isn't it?
Thanks a lot friends.
Jul 23 '08 #11

P: n/a
On Jul 23, 5:05 am, anchitg...@gmail.com wrote:
On Jul 22, 5:07 pm, Lionel B <m...@privacy.netwrote:
On Mon, 21 Jul 2008 20:28:31 -0700, anchitgood wrote:
Hey, I have developed the following code and it is
executing well on windows. But I don't have LINUX
installed on my system. I would be grateful to you guys if
you check whether this code is working fine on linux. I
know that C++ is independent of OS, but still check it on
g++ compiler.
You might first want to test-compile it on Comeau Online:
http://www.comeaucomputing.com/tryitout/
Comeau has a reputation as one of the most
standards-compliant compilers around, and you may specify an
"architecture" to compile your code under.
yeah, its showing compile succeded on comeau link. Compile
succeded on every red hat platform and also on Linux alpha. So
this has done the job, isn't it?
Just a nit, but compile succeeded doesn't mean that it will run.
You can still have undefined behavior that just happens to work
with the current version of the compiler you're using, at least
with the options you use to compile.

(Note that this really isn't a portability issue, per se, unless
it is a case of the code depending on behavior that actually is
guaranteed by your compiler, but not by the standard. It's a
sad fact of life that the fact that a program runs doesn't mean
that it is correct, even on a given platform.)

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jul 23 '08 #12

P: n/a
On Wed, 23 Jul 2008 01:07:54 -0700, James Kanze wrote:
On Jul 23, 5:05 am, anchitg...@gmail.com wrote:
>On Jul 22, 5:07 pm, Lionel B <m...@privacy.netwrote:
On Mon, 21 Jul 2008 20:28:31 -0700, anchitgood wrote:
Hey, I have developed the following code and it is executing well
on windows. But I don't have LINUX installed on my system. I would
be grateful to you guys if you check whether this code is working
fine on linux. I know that C++ is independent of OS, but still
check it on g++ compiler.
You might first want to test-compile it on Comeau Online:
>http://www.comeaucomputing.com/tryitout/
Comeau has a reputation as one of the most standards-compliant
compilers around, and you may specify an "architecture" to compile
your code under.
>yeah, its showing compile succeded on comeau link. Compile succeded on
every red hat platform and also on Linux alpha. So this has done the
job, isn't it?

Just a nit, but compile succeeded doesn't mean that it will run. You can
still have undefined behavior that just happens to work with the current
version of the compiler you're using, at least with the options you use
to compile.
More than a nit: I should have made clear that this establishes that the
code compiles, rather than (as the OP requested) that it "works fine" on
any particular platform.
(Note that this really isn't a portability issue, per se, unless it is a
case of the code depending on behavior that actually is guaranteed by
your compiler, but not by the standard. It's a sad fact of life that
the fact that a program runs doesn't mean that it is correct, even on a
given platform.)
I guess it could have been a portability issue if the OP's code happened
to call some system-specific library functionality (e.g. something POSIX-
or Windows-specific). The OP's system("cls") call is arguably system-
specific by definition - although the `system' part is perfectly
portable, of course... ;-)

--
Lionel B
Jul 23 '08 #13

P: n/a
On Jul 23, 12:03 pm, Lionel B <m...@privacy.netwrote:

[...]
(Note that this really isn't a portability issue, per se,
unless it is a case of the code depending on behavior that
actually is guaranteed by your compiler, but not by the
standard. It's a sad fact of life that the fact that a
program runs doesn't mean that it is correct, even on a
given platform.)
I guess it could have been a portability issue if the OP's
code happened to call some system-specific library
functionality (e.g. something POSIX- or Windows-specific). The
OP's system("cls") call is arguably system- specific by
definition - although the `system' part is perfectly portable,
of course... ;-)
Using explicitly implementation defined behavior, or undefined
behavior that is defined by your compiler or system, or
implementation specific extensions, or counting on additional
standards (Posix, Windows, etc.) create portability problems.
My point was just that in general, you can have problems when
"porting" even if the code doesn't have "portability" problems;
the fact that is seemed to work on one system could be purely
due to change. The meaning of the string passed to system() is
one of these. (I might add that I haven't actually studied the
original code in detail, and so can't say whether it has or
doesn't have such problems.)

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jul 23 '08 #14

P: n/a
an********@gmail.com wrote:
Hey, I have developed the following code and it is executing well on
windows. But I don't have LINUX installed on my system. I would be
grateful to you guys if you check whether this code is working fine on
linux. I know that C++ is independent of OS, but still check it on g++
compiler.
If all you need to do is to confirm that g++ compiles it, then install
mingw on Windows.
Jul 24 '08 #15

This discussion thread is closed

Replies have been disabled for this discussion.