Re: why does it crash?
From: Moonlit (alt.spam_at_jupiter.universe)
Date: 10/10/03
- Next message: lilburne: "Re: copy ctor question"
- Previous message: Victor Bazarov: "Re: why does it crash?"
- In reply to: Developwebsites: "why does it crash?"
- Next in thread: Xenos: "Re: why does it crash?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 10 Oct 2003 21:28:17 +0200
Hi,
Could you be more specific at which line it crashes, I compiled it and it
runs for me (that doesn't say it is correct though).
BTW Using vectors and STL stuff would have reduced your code to a few lines.
To get some ideas:
#include <algorithm>
#include <string>
using namespace std;
class CCityInfo
{
string CityName;
int Temp;
// Constructor stuff and init etc public keywords Get and Put functions
etc..
bool operator <( const CCityInfo& City1 ) const
{
return Temp < City1.Temp;
}
};
vector<CCityInfo> Cities;
sort( Cities.begin(), Cities.end() );
-------------------------------------------------------
[root@moonlit root]# ./r
Please enter name of city#1: 1
Please enter 1's temp: 2
Another city?(Y/N)y
Please enter name of city#2: 3
Please enter 3's temp: 2
Another city?(Y/N)n
name of city temperature
1 2
3 2
name of city temperature
1 2
3 2
------------------------------------------------------------
"Developwebsites" <developwebsites@aol.combatSPAM> wrote in message
news:20031010150519.17356.00000063@mb-m03.aol.com...
> this program compiles, but crashes when run.
> whats wrong with it?
>
> #include<iostream.h>
> #include<iomanip.h>
>
> int numb_cities=0;
> const int MAX = 120;
>
> class Cities {
> private:
> char cityname[MAX][MAX];//an array of 120 cities.
> int temp[MAX];
>
> public:
> void input();
> void output();
> void sort();
> };
>
>
> void Cities::input()
> {
> char y_n;
> do{
> cout<<"\n\n";
> cout<<"Please enter name of city#"<<numb_cities+1<<": ";
> cin>>cityname[numb_cities];
> cout<<"\nPlease enter "<<cityname[numb_cities]<<"'s temp: ";
> cin>>temp[numb_cities];
> numb_cities++;
> cout<<"\nAnother city?(Y/N)";
> cin>>y_n;
> }while(y_n =='y' || y_n =='Y');
> cout<<"\n\n";
> }
>
> void Cities::output()
> {
> cout<<"\n"<<"name of city"
> <<" temperature"
> <<"\n";
> for(int t=0;t<numb_cities;t++)
> {
> cout<<setw(5)<<cityname[t]<<setw(15)<<temp[t]<<"\n";
> }
> }//close output
>
> void Cities::sort()
> {
> char citynametemp[MAX][MAX];
> int tempt;
> for(int a=0;a<numb_cities;a++) {
> for(int b=a+1; b<numb_cities;b++) {
> if (temp[a]<temp[b]) {
> tempt = temp[a];
> temp[a] = temp[b];
> temp[b] = tempt;
> citynametemp[MAX][MAX] = cityname[a][MAX];
> cityname[a][MAX] = cityname[b][MAX];
> cityname[b][MAX] = citynametemp[MAX][MAX];
> }//close if
> }//close b loop
> }//close a loop
> }//close sort
>
>
> int main()
> {
> Cities info;
>
> info.input();
> info.output();
> info.sort();
> info.output();
> return 0;
> }
> --------------------------------------------------
> remove *batSPAM* to e-mail me
> --------------------------------------------------
- Next message: lilburne: "Re: copy ctor question"
- Previous message: Victor Bazarov: "Re: why does it crash?"
- In reply to: Developwebsites: "why does it crash?"
- Next in thread: Xenos: "Re: why does it crash?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|