Tabel maken van structures

Status
Niet open voor verdere reacties.

SETMRC

Gebruiker
Lid geworden
15 feb 2007
Berichten
23
Hallo, dit is de code die ik tot nu toe al heb:

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

struct SPunt2D
{
int iX;
int iY;
};

struct SPunt2DTabel
{
int iX_Een, iX_Twee, iX_Drie, iX_Vier, iX_Vijf;
int iY_Een, iY_Twee, iY_Drie, iY_Vier, iY_Vijf;
};

void vFLees( SPunt2D& oPunt );
void vFPrint( const SPunt2D& oPunt );
void vFLees( SPunt2DTabel& oTabel );
void vFPrint( const SPunt2DTabel& oTabel );

int main()
{
SPunt2D oPunt;
cout << "Geef de coordinaten van het punt in: " << endl;
vFLees( oPunt );
cout << "De ingevoerde gegevens zijn: " << endl;
vFPrint( oPunt );
SPunt2D oTabel;
cout << "Geef 5 koppels coordinaten in: " << endl;
vFLees( oTabel );
cout << "De ingegeven koppels zijn: " << endl;
vFPrint( oTabel );
}
void vFLees( SPunt2D& oPunt )
{
cin >> oPunt.iX >> oPunt.iY;
flushall();
}

void vFPrint( const SPunt2D& oPunt )
{
cout << "De ingegeven X-coordinaat is: " << oPunt.iX << endl;
cout << "De ingegeven Y-coordinaat is: " << oPunt.iY << endl;
}

void vFLees( SPunt2DTabel& oTabel )
{
cin >> oTabel.iX_Een >> oTabel.iY_Een >>
oTabel.iX_Twee >> oTabel.iY_Twee >>
oTabel.iX_Drie >> oTabel.iY_Drie >>
oTabel.iX_Vier >> oTabel.iY_Vier >>
oTabel.iX_Vijf >> oTabel.iY_Vijf;
}

void vFPrint( const SPunt2DTabel& oTabel )
{
cout << setw(15) << "De ingegeven koppels zijn" << endl;
cout << "=========================" << endl << endl;
cout << "X-coordinaat" << setw(15) <<"Y-coordinaat" << endl;
cout << "============" << setw(15) << "===========" << endl;
cout << oTabel.iX_Een << setw(15) << oTabel.iY_Een << endl;
cout << oTabel.iX_Twee << setw(15) << oTabel.iY_Twee << endl;
cout << oTabel.iX_Drie << setw(15) << oTabel.iY_Drie << endl;
cout << oTabel.iX_Vier << setw(15) << oTabel.iY_Vier << endl;
cout << oTabel.iX_Vijf << setw(15) << oTabel.iY_Vijf << endl;
}


Ik heb 2 structures gedeclareerd (SPunt2D en SPunt2DTabel). Nu wordt er gevraagd om 5 koppels (X en Y) in een tabel af te drukken. De functie die dit hoort te doen is vFPrint( const SPunt2DTabel& oTabel). Als je het programma runt zie je dat ik telkens 2 keer hetzelfde op mn scherm krijg. Kan iemand mij helpen om een tabel af te drukken ?
 
Ik heb ondertussen de vFLees functie van de tabel aangepast:

void vFLees( SPunt2DTabel& oTabel )
{
cout << "Geef het eerste koppel in: ";
cin >> oTabel.iX_Een >> oTabel.iY_Een;
flushall();
cout << "Geef het tweede koppel in: ";
cin >> oTabel.iX_Twee >> oTabel.iY_Twee;
flushall();
cout << "Geef het derde koppel in: ";
cin >> oTabel.iX_Drie >> oTabel.iY_Drie;
flushall();
cout << "Geef het vierde koppel in: ";
cin >> oTabel.iX_Vier >> oTabel.iY_Vier;
flushall();
cout << "Geef het vijfde koppel in: ";
cin >> oTabel.iX_Vijf >> oTabel.iY_Vijf;
flushall();
}


Maar ik heb nog altijd hetzelfde probleem ....
 
never mind .. tis al opgelost:


#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

// structuren - klassen
struct SPunt2D
{
int iX, iY;
};

// constanten
const int iAANTAL = 5;

// prototypes (declaratie functies)
void vFLees(SPunt2D &oPunt);
void vFAfdrukPunt(const SPunt2D &oPunt);
double dFAfstand(const SPunt2D &oPunt1, const SPunt2D &oPunt2);
void vFAfdrukTabellen(SPunt2D &oRefPunt, SPunt2D aoPunten[], double adAfstand[], int iAantal);

// Hoofdprogramma
void main()
{
SPunt2D oRefPunt, aoPunten[iAANTAL];
double adAfstand[iAANTAL];
cout << "Geef een referentiepunt in:" << endl;
vFLees(oRefPunt);
cout << "Geef " << iAANTAL << " punten in" << endl;
for(int i = 0; i < iAANTAL; i++)
{
cout << (i+1) << "e punt:" << endl;
vFLees(aoPunten);
adAfstand = dFAfstand(aoPunten, oRefPunt);
}
vFAfdrukTabellen(oRefPunt, aoPunten, adAfstand, iAANTAL);
}

// Definities functies
void vFLees(SPunt2D &oPunt)
{
cout << "Geef X- en Y-coordinaat" << endl;
cin >> oPunt.iX >> oPunt.iY;
}

void vFAfdrukPunt(const SPunt2D &oPunt)
{
cout << "(" << oPunt.iX << ", " << oPunt.iY << ")";
}

double dFAfstand(const SPunt2D &oPunt1, const SPunt2D &oPunt2)
{
double dVerschilX = static_cast<double> (oPunt1.iX - oPunt2.iX);
double dVerschilY = static_cast<double> (oPunt1.iY - oPunt2.iY);
double dAfstand = sqrt(dVerschilX * dVerschilX + dVerschilY * dVerschilY);
return dAfstand;
}

void vFAfdrukTabellen(SPunt2D &oRefPunt, SPunt2D aoPunten[], double adAfstand[], int iAantal)
{
cout << "De coordinaten van het referentiepunt : ";
vFAfdrukPunt(oRefPunt);
cout << endl << endl;
cout << "(X, Y) Afstand tot refpunt" << endl
<< "------ -------------------" << endl << endl;
for(int i = 0; i < iAantal; i++)
{
vFAfdrukPunt(aoPunten);
cout << " " << adAfstand << endl;
}
}
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan