GIDForums  

Go Back   GIDForums > Computer Programming Forums > CPP / C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 30-Nov-2004, 09:58
sammacs sammacs is offline
New Member
 
Join Date: Nov 2004
Posts: 12
sammacs is on a distinguished road

Fairly simple classes help please


Hi all, how's it going?
I'm a C++ novice and have this bad habit of writing code in one big 'main' file and then trying to split it up into classes and functions afterwards. The following program works fully but I need to have 'Town' as a class that stores the name, poulation and area (a town.h file). I know only the very basics about classes and so don't really know where to start.
I'd appreciate any help
thanks
Sam

[c]
#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <string>

//#include "town.h"

using namespace std;

int main()
{
int c,g;
int n = 0;

cout << "How many towns would you like to enter? ";
cin >> c;

string *narray = new string[c];
double *parray = new double[c];
double *aarray = new double
CPP / C++ / C Code:
;
    
    while (n <= (c-1))
    {
        cout << "\nPlease enter the name of town " << (n+1) << ": ";
        cin >> narray[n];
        cout << "Please enter the population: ";
        cin >> parray[n];
        cout << "Please enter the area (km): ";
        cin >> aarray[n];
        cout << narray[n] << " has a population of " << parray[n]
                << " and an area of " << aarray[n] << "km" << endl;
        n++;
    }
    
    n = 0;
    g = 0;
    
    while (g < c)
    {
        g++;
        if (parray[n] < parray[g])
        {
            n = g;
        }
    }
    
    cout << "\n" << narray[n] << " has the largest population" << endl;
    
    
    n = 0;
    g = 0;
    
    while (g < c)
    {
        g++;
        if (aarray[n] < aarray[g])
        {
            n = g;
        }
    }
    
    cout << narray[n] << " has the largest area" << endl;
    
    
    n = 0;
    g = 0;
    
    while (g < c)
    {
        g++;
        if ((aarray[n]/parray[n]) < (aarray[g]/parray[g]))
        {
            n = g;
        }
    }
    
    cout << narray[n] << " has the largest population density" << endl;
    
    
    delete[] narray;
    delete[] parray;
    delete[] aarray;
    
    getch();
    return 0;
}
 

Recent GIDBlog2nd Week of IA Training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
help with classes bucho MS Visual C++ / MFC Forum 3 20-Oct-2004 06:16
First time using classes crystalattice CPP / C++ Forum 6 13-Oct-2004 08:21
finding a simple cms dopee MySQL / PHP Forum 1 23-Mar-2004 09:30
ClassView not showing my classes (VC++, namespace, headers) ?!?!? djovanov CPP / C++ Forum 1 13-Jan-2004 04:54

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 22:46.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.