473,811 Members | 2,879 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Code running on LINUX?

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<iostre am>
#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(st ring l)
{
licnumber=l;
}

void setminutesparke d(int mnp)
{
minutesparked=m np;
}

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

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

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

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

int getminutesparke d() const
{
return (minutesparked) ;
}

void print();
};

void parkedcar::prin t() //outside class definition
{
cout<<"Car Make :"<<getmake()<< endl;
cout<<"Car Model :"<<getmodel()< <endl;
cout<<"Car License Number :"<<getlicnumbe r()<<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()<<e ndl;
}
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(minpurch ased);
}
void print()
{
cout<<"Mins purchased are"<<getminpur chased();
}
};

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(badgenum ber);
}
parkingticket* patrol(parkingt icket pc1, parkingmeter pc2) //Patrol
function
{
if ( pc1.getminutesp arked() < pc2.getminpurch ased() ||
pc1.getminutesp arked() == pc2.getminpurch ased() )
{
return NULL; //No crimes
}
else //Illegal parking
{
tck[m].getticket(pc1. getminutesparke d() - pc2.getminpurch ased());

cout<<"--------------------------------------------------------------------------------"<<endl;
tck[m].showfine();
ticket=&tck[m];
return(ticket);
}
}
void print()
{
cout<<"Name: "<<getname()<<e ndl;
cout<<"Badge Number: "<<getbadgenumb er()<<endl;
}
};
void intro()
{
cout<<"******** *************** *************** *************** *************** ************"<< endl;
cout<<" THIS IS PARKING TICKET SIMULATOR"<<end l;
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<<end l;
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.setbadg enumber(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(l ic);

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].setminutespark ed(parmin);
int purmin; //The number of minutes purchased
cout<<"Minutes purchased :";
cin>>purmin;
meter[m].setminpurchase d(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<<"No n-permitted vehicle ::"<<endl;
ticket->print(); // Display the ticket information.

cout<<"--------------------------------------------------------------------------------"<<endl;
ticket = NULL;
}
k[m] = tck[m].getminutespark ed() - meter[m].getminpurchase d();
cout<<endl<<end l<<endl<<endl<< endl;

cout<<"________ _______________ _______________ _______________ _______________ ____________"<< endl;
cout<<"Enter your choice -"<<endl;
cout<<"0 - Patrol another car 1 - View cars patrolled"<<end l;
choice();
}while (c == 0);

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

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
14 2281
On Jul 22, 5:07*pm, Lionel B <m...@privacy.n etwrote:
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 "architectu re" 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
On Jul 23, 5:05 am, anchitg...@gmai l.com wrote:
On Jul 22, 5:07 pm, Lionel B <m...@privacy.n etwrote:
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
"architectu re" 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 objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jul 23 '08 #12
On Wed, 23 Jul 2008 01:07:54 -0700, James Kanze wrote:
On Jul 23, 5:05 am, anchitg...@gmai l.com wrote:
>On Jul 22, 5:07 pm, Lionel B <m...@privacy.n etwrote:
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 "architectu re" 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
On Jul 23, 12:03 pm, Lionel B <m...@privacy.n etwrote:

[...]
(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 "portabilit y" 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 objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jul 23 '08 #14
an********@gmai l.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2897
by: walter | last post by:
I have many computers running Linux. For some reasons, the versions are not the same. Now, I want to write a C program to run on them. "Compile once and run everywhere". Is there anything I have to take care of? Thanks
4
2928
by: Rajeev | last post by:
I want to calculate the running time of my program, which runs for a long time(~ a day). This is what I am doing in my code: #include <time.h> clock_t tend, tstart; tstart = clock(); \* Body of Code *\
21
3564
by: sachin dooble | last post by:
is there any method where i can run my linux code that is all the a.out i made on linux to run on windows. plz tell me the way.
3
3040
by: Double Echo | last post by:
Hi all, I'm using PHP 4.4.2, and use PHP on both the command-line and the web. I am running PHP on SuSE 10 Linux , in a VMware 5.5 workstation, using Apache 2.0.55 , on my Dell laptop. Everything has been running flawlessly without problems. Very amazing to use VMware, it has worked beautifully. uname -a
0
1553
by: Peter Chant | last post by:
I hope no one minds me running this past them. I'm running a linux machine with with apache, php and mysql. This is not accessable from the internet. I want a server that is visable to the internet. For that purpose I am running a user mode linux machine and using apache on that as the external looking web server. This means that stuff I want to see on the outside is on a copy of apache that is doing little and does not get messed...
15
4651
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to communicate with a MySQL database table on a web server, from inside of my company's Access-VBA application. I know VBA pretty well but have never before needed to do this HTTP/XML/MySQL type functions.
4
1882
by: Stylus277 | last post by:
Hello, I am working with a client that has an old Linux server with a custom cbase program. The server has been humming along since 1989, with the exception of a HDD fail in 1994, which was replaced restored from tape. The uptime on this beast is like 12 years and counting. Just this week the last linux terminal was replaced with a new Dell running XP Pro. The client wants to keep the software but wants the space where the server fits...
9
6709
by: shorti | last post by:
db2 V8.2 I have been looking for a good way to log the 'reason code' when we hit an sqlcode that uses them. From what I can tell the reason code is stored in sqlca.sqlerrmc. But, there seems to be other information stored in this string besides the reason code. The DB2 Info Center website states that sqlca.sqlerrml identifies whether sqlerrmc contains valid data and the length of the data so I added code that would copy the content...
2
1662
by: peter | last post by:
I'm not sure if this query should be directed to comp.lang.python or comp.os.linux.misc so I intend to post it to both with apologies if it's inappropriate on either. I have a small python utility which I wrote myself and which crawls through a directory comparing all possible pairs of files. Under Windows it works fine, while the same code under Linux (Fedora Core 3) works for a while then starts continuously throwing up the following...
0
9603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10393
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7664
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6882
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4334
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.