lefantome
13-01-2009, 18:54
file porto.h
Codice:
#include<fstream>
#include<cstdlib>
#include<iostream>
using namespace std;
struct section {
int boat;
int ord;
int max;
int* matricola;
section* pun;
};
class porto {
public:
section* p0;
porto() { p0->pun == 0; p0->ord =0;}
bool adds(int max, int pos);
bool addb( int m);
void stampa();
};
file porto.cpp
Codice:
#include"porto.h"
bool porto::adds(int max, int pos) {
section* p;
section* q;
section* r;
for (p=p0;p !=0;p= p->pun)
{
q=p->pun;
if (p->ord<pos && q->ord>=pos)
{
r = new section;
r->max = max;
r->boat=0;
r->matricola= new int[max];
for (int i=0;i<max;i++)
{ r->matricola[i]=0;}
r->ord = pos;
r->pun = q;
p->pun = r;
return true;
}
cout<<"error"<<endl;
return false;
}
if (p0->pun == 0)
{ p0->boat= 0;
p0->max = max;
p0->matricola= new int[max];
return true;}
}
bool porto::addb(int m) {
section* p = p0;
for (;p->pun !=0;p=p->pun)
{
if (p->boat < p->max) {
for (int i=0;i<p->max;i++)
{ if (p->matricola[i] ==0)
{ p->matricola[i]== m;
p->boat++;
return true;}
}
}
if (p0->ord ==0){return false;}
}}
void porto::stampa() {
section* p;
for (p=p0;p !=0;p= p->pun)
{
cout<<p->ord<<": ";
for (int i=0;i<p->max;i++)
{
cout<<p->matricola[i]<<", ";}
cout<<endl;}
return;}
file main.cpp
Codice:
#include"porto.h"
int main()
{porto a;
a.adds(2,0);
a.adds(3,1);
a.adds(3,0);
a.adds(2,2);
a.addb(12);
a.addb(22);
a.addb(15);
a.stampa();
system("pause");
return 0;
}
Dove può essere l'errore?credo con qualche puntatore ma mi crasha con devcpp. help ho l'esame venerdi! :doh: :banned:
Codice:
#include<fstream>
#include<cstdlib>
#include<iostream>
using namespace std;
struct section {
int boat;
int ord;
int max;
int* matricola;
section* pun;
};
class porto {
public:
section* p0;
porto() { p0->pun == 0; p0->ord =0;}
bool adds(int max, int pos);
bool addb( int m);
void stampa();
};
file porto.cpp
Codice:
#include"porto.h"
bool porto::adds(int max, int pos) {
section* p;
section* q;
section* r;
for (p=p0;p !=0;p= p->pun)
{
q=p->pun;
if (p->ord<pos && q->ord>=pos)
{
r = new section;
r->max = max;
r->boat=0;
r->matricola= new int[max];
for (int i=0;i<max;i++)
{ r->matricola[i]=0;}
r->ord = pos;
r->pun = q;
p->pun = r;
return true;
}
cout<<"error"<<endl;
return false;
}
if (p0->pun == 0)
{ p0->boat= 0;
p0->max = max;
p0->matricola= new int[max];
return true;}
}
bool porto::addb(int m) {
section* p = p0;
for (;p->pun !=0;p=p->pun)
{
if (p->boat < p->max) {
for (int i=0;i<p->max;i++)
{ if (p->matricola[i] ==0)
{ p->matricola[i]== m;
p->boat++;
return true;}
}
}
if (p0->ord ==0){return false;}
}}
void porto::stampa() {
section* p;
for (p=p0;p !=0;p= p->pun)
{
cout<<p->ord<<": ";
for (int i=0;i<p->max;i++)
{
cout<<p->matricola[i]<<", ";}
cout<<endl;}
return;}
file main.cpp
Codice:
#include"porto.h"
int main()
{porto a;
a.adds(2,0);
a.adds(3,1);
a.adds(3,0);
a.adds(2,2);
a.addb(12);
a.addb(22);
a.addb(15);
a.stampa();
system("pause");
return 0;
}
Dove può essere l'errore?credo con qualche puntatore ma mi crasha con devcpp. help ho l'esame venerdi! :doh: :banned: