I need to do a c++ program fo school

It is intended that it builds a program that allows the management of reservations of a
show room with registration of event name, date, time, duration and customer name.

1) It should include:
a) The program should be structured using modular programming, whenever
this is applicable (functions and procedures);
b) Comments and parameters;
c) At least one text file;
d) A control that verifies that the files already exist in the disk and message in case
of error;
e) Allow the insertion, consultation and modification of the data of the files;
f) Contain a menu system that allows navigation throughout the project;
g) Allow to search and query the data of the file by a field (for example by
date).
h) Allow the last record to be displayed on the monitor.
Please note that this is not a homework site. We won't do your homework for you. The purpose of homework is that you learn by doing. However we are always willing to help solve problems you encountered, correct mistakes you made in your code and answer your questions.

We didn't see your attempts to solve this problem yourself and so we cannot correct mistakes you didn't made and answer questions you didn't ask. To get help you should do something yourself and get real problems with something. If your problem is "I don't understand a thing", then you should go back to basics and study again.
#include <stdio.h>
#include <iostream>

using namespace std;

int op;

struct registro { //estrutura do registro
char nomeevento[40];
char nome[40];
char data[20];
char hora[20];
char duracao[40];
char status;
} reg;
char url[]="gestaoderesrvas.txt";
FILE *fp;

void criar()
{

fp=fopen(url, "w");

if(fp==NULL)
{
cout<<"Ficheiro não existe"<<endl;
}else

do
{
printf("\n Digite o nome do evento ou <FIM> para sair:\n\n");
cin.ignore();
gets(reg.nomeevento);

if (((reg.nomeevento,"fim")!=0)&&((reg.nomeevento,"FIM")!=0)){
printf("\n Nome do cliente:"); gets(reg.nome);
printf("\n Data:"); gets(reg.data);
printf("\n Hora:"); gets(reg.hora);
printf("\n Duração:"); gets(reg.duracao);

printf("\n Erro de gravação!!");
}
else
{ printf("\n Gravação feita com sucesso...\n\n");}
}while(((reg.nomeevento,"fim")!=0)&&((reg.nomeevento,"FIM")!=0));
fclose(fp);
}


void sobre() { //Diz ao utilizador por quem foi feito o programa

printf("\n\n");
printf("\t########################################################\n");
printf("\t# Programa feito por.: gheorghe #\n");
printf("\t########################################################\n\n\n");
printf("\t\t\tTecle <ENTER> para voltar");
}



void busca()
{
int achou=-1,posicao=0;
char datap[40];
{
fp=fopen(url, "w");

if(fp==NULL)
cout<<"Ficheiro não existe"<<endl;


}

printf("\nDigite a data a ser procurada:");
gets(datap);
rewind(fp);
while((!feof(fp))&&(achou==-1))
{
if (!feof(fp))
{if ((datap, reg.data)==0)
{if (reg.status=='0')
{posicao=-2;}
achou=1;
}
else{posicao++;}
}
else{posicao=-1;}
}
if (achou==-1)
{posicao=-1;}
fclose(fp);
cout<<posicao;
}



void alterar(void){
int pos;
if (pos==-1)
{
printf("\nNome inexistente no arquivo");

}
else if(pos==-2)
{
printf("\nNome inexistente no arquivo!");

}
else
{
fp=fopen(url, "w");

printf("\nNome :%s",reg.nome);
printf("\nData:%s",reg.data);
printf("\nHora:%s",reg.hora);
printf("\nDuração:%s",reg.duracao);

printf("\nDigite as informacoes corretas:");
printf("\nNome:");
gets(reg.nome);
printf("\nData:");
gets(reg.data);
printf("\nHora:");
gets(reg.hora);
printf("\nDuração:");
gets(reg.duracao);

reg.status='1';
fseek(fp,pos*sizeof(struct registro),SEEK_SET);
{
printf("\nErro na gravacao...");
}

}
fclose(fp);
}



void menu()
{

system("color 3");
cout<<"\n\n\n";
cout<<"\t########################################################\n";
cout<<"\t## ##\n";
cout<<"\t## Programa Gestão de reservas ##\n";
cout<<"\t## ##\n";
cout<<"\t########################################################\n\n\n";
cout<<"\t\t\t\t\ 1-Inserir dados\n";
cout<<"\t\t\t\t\ 2-Consultar os dados por data\n";
cout<<"\t\t\t\t\ 3-Alterar dados\n";
cout<<"\t\t\t\t\ 4-Sobre\n";
cout<<"\t\t\t\t\ 5-Sair\n";
cout<<"\nEscolha a sua opção: ";
cin>>op;
switch(op)
{
case 1:
{
criar();
break;
}

case 2:
{
busca();
break;
}

case 3:
{
alterar();
break;
}

case 4:
{
sobre();
break;
}

case 5:
{
cout<<"Obrigado, volte sempre.\n";
break;
}
}

}

main()
{

setlocale(LC_ALL,"Portuguese");
menu();

do{
system("cls");
menu();
system("pause");

}
while(op!=5);
}
It looks like this is mostly using C strings. I'll assume that's required, but if it isn't, you'd be much better off using C++ strings instead.

Use strcmp() to compare strings.
\ isn't a valid escape sequence.
At the beginning of alterar(), you use pos before it's initialized. I've left that bug in because I'm not sure what you need.

This version compiles and should help you get further:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#include <stdio.h>
#include <iostream>
#include <cstring>
using namespace std;

int op;

struct registro
{				//estrutura do registro
    char nomeevento[40];
    char nome[40];
    char data[20];
    char hora[20];
    char duracao[40];
    char status;
} reg;
char url[] = "gestaoderesrvas.txt";
FILE *fp;

void
criar()
{

    fp = fopen(url, "w");

    if (fp == NULL) {
	cout << "Ficheiro não existe" << endl;
    } else

	do {
	    printf("\n Digite o nome do evento ou <FIM> para sair:\n\n");
	    cin.ignore();
	    gets(reg.nomeevento);

	    if ((strcmp(reg.nomeevento, "fim") != 0) && (strcmp(reg.nomeevento, "FIM") != 0)) {
		printf("\n Nome do cliente:");
		gets(reg.nome);
		printf("\n Data:");
		gets(reg.data);
		printf("\n Hora:");
		gets(reg.hora);
		printf("\n Duração:");
		gets(reg.duracao);

		printf("\n Erro de gravação!!");
	    } else {
		printf("\n Gravação feita com sucesso...\n\n");
	    }
	} while ((strcmp(reg.nomeevento, "fim") != 0) && (strcmp(reg.nomeevento, "FIM") != 0));
    fclose(fp);
}

void
sobre()
{						 //Diz ao utilizador por quem foi feito o programa

    printf("\n\n");
    printf("\t########################################################\n");
    printf("\t# Programa feito por.: gheorghe #\n");
    printf("\t########################################################\n\n\n");
    printf("\t\t\tTecle <ENTER> para voltar");
}

void
busca()
{
    int achou = -1, posicao = 0;
    char datap[40];
    {
	fp = fopen(url, "w");

	if (fp == NULL)
	    cout << "Ficheiro não existe" << endl;

    }

    printf("\nDigite a data a ser procurada:");
    gets(datap);
    rewind(fp);
    while ((!feof(fp)) && (achou == -1)) {
	if (!feof(fp)) {
	    if (strcmp(datap, reg.data) == 0) {
		if (reg.status == '0') {
		    posicao = -2;
		}
		achou = 1;
	    } else {
		posicao++;
	    }
	} else {
	    posicao = -1;
	}
    }
    if (achou == -1) {
	posicao = -1;
    }
    fclose(fp);
    cout << posicao;
}

void
alterar(void)
{
    int pos;
    if (pos == -1) {
	printf("\nNome inexistente no arquivo");

    } else if (pos == -2) {
	printf("\nNome inexistente no arquivo!");

    } else {
	fp = fopen(url, "w");

	printf("\nNome :%s", reg.nome);
	printf("\nData:%s", reg.data);
	printf("\nHora:%s", reg.hora);
	printf("\nDuração:%s", reg.duracao);

	printf("\nDigite as informacoes corretas:");
	printf("\nNome:");
	gets(reg.nome);
	printf("\nData:");
	gets(reg.data);
	printf("\nHora:");
	gets(reg.hora);
	printf("\nDuração:");
	gets(reg.duracao);

	reg.status = '1';
	fseek(fp, pos * sizeof(struct registro), SEEK_SET);
	{
	    printf("\nErro na gravacao...");
	}

    }
    fclose(fp);
}

void
menu()
{

    system("color 3");
    cout << "\n\n\n";
    cout << "\t########################################################\n";
    cout << "\t## ##\n";
    cout << "\t## Programa Gestão de reservas ##\n";
    cout << "\t## ##\n";
    cout << "\t########################################################\n\n\n";
    cout << "\t\t\t\t 1-Inserir dados\n";
    cout << "\t\t\t\t 2-Consultar os dados por data\n";
    cout << "\t\t\t\t 3-Alterar dados\n";
    cout << "\t\t\t\t 4-Sobre\n";
    cout << "\t\t\t\t 5-Sair\n";
    cout << "\nEscolha a sua opção: ";
    cin >> op;
    switch (op) {
    case 1:
	{
	    criar();
	    break;
	}

    case 2:
	{
	    busca();
	    break;
	}

    case 3:
	{
	    alterar();
	    break;
	}

    case 4:
	{
	    sobre();
	    break;
	}

    case 5:
	{
	    cout << "Obrigado, volte sempre.\n";
	    break;
	}
    }

}

main()
{

    setlocale(LC_ALL, "Portuguese");
    menu();

    do {
	system("cls");
	menu();
	system("pause");

    }
    while (op != 5);
}

Topic archived. No new replies allowed.