I'm going to redo the code for C ++ without using what's C style.
It is appropriate to use a map , which was described as a requirement. If the requirement is wrong then the solution would be another.
I changed to class because it is more idiomatic for this type of use in C ++. I used string
instead of array of char
which is C. thing. I used better names.
I do not like this Inserir()
in the class, but for an exercise it's fine. Also should not use double
for monetary value .
There are other minor problems that are not serious for an exercise.
I printed it at the end and tested it with out-of-order data to show it is in alphabetical order.
There is probably a more complex solution that is better than this that has its own difficulties.
#include <iostream>
#include <string>
#include <map>
using namespace std;
class FichaInscricao {
public:
string Nome;
string Cpf;
string Logradouro;
string Bairro;
string Cidade;
string Estado;
string Email;
string Telefone;
double SalarioFamiliar = 0;
int QuantidadePessoas = 0;
double RendaPerCapita = 0;
void Inserir() {
cout << "Nome: ";
cin >> Nome;
cout << "CPF: ";
cin >> Cpf;
cout << "Logradouro: ";
cin >> Logradouro;
cout << "Bairro: ";
cin >> Bairro;
cout << "Cidade: ";
cin >> Cidade;
cout << "Estado: ";
cin >> Estado;
cout << "Email: ";
cin >> Email;
cout << "Telefone: ";
cin >> Telefone;
cout << "Salario Total da Familia: ";
cin >> SalarioFamiliar;
cout << "Quantidade de pessoas na sua casa: ";
cin >> QuantidadePessoas;
RendaPerCapita = SalarioFamiliar / QuantidadePessoas;
}
};
int main() {
map<string, FichaInscricao> fichario;
int op = 1;
while (op == 1) {
FichaInscricao ficha;
ficha.Inserir();
fichario.emplace(ficha.Nome, ficha);
cout << "\nNovo cadastro?\n"
<< "1 - SIM\n"
<< "0 - NAO\n";
cin >> op;
}
for (const auto &ficha : fichario) {
std::cout << ficha.first << " => " << ficha.second.Cpf << '\n';
}
}
See working on ideone and in C ++ Shell .