Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //HEADER.H
- #define N 100
- typedef char stringa[N];
- typedef struct{
- stringa nome;
- stringa numero;
- } persona;
- typedef persona tabella[N];
- void letturatabella(tabella,persona,int&);
- int verifica(tabella,int,persona);
- void stampa_agenda(tabella,int);
- void stampa_record(persona);
- int ricerca_contatto(tabella,int,stringa);
- //BODY.CPP
- #include <iostream>
- #include "libreria.h"
- #include <string.h>
- using namespace std;
- int verifica(tabella t1,int r,persona p1){
- for(int i=0;i<r;i++){
- if(strcmp(t1[i].nome,p1.nome)==0)
- return -1;
- }
- return 1;
- }
- void letturatabella(tabella t1,persona p1,int& r){
- if(verifica(t1,r,p1)==-1)
- cout<<"Contatto gia' inserito.\n";
- else{
- t1[r]=p1;
- r++;
- cout<<" -> Contatto salvato\n";
- }
- }
- void stampa_agenda(tabella t1,int r){
- for(int i=0;i<r;i++){
- cout<<" Contatto "<<i+1<<endl;
- stampa_record(t1[i]);
- }
- }
- void stampa_record(persona p1){
- cout<<" Nome: "<<p1.nome<<endl;
- cout<<" Numero: "<<p1.numero;
- cout<<endl;
- }
- int ricerca_contatto(tabella t1,int r,stringa nome){
- int pos=-1,i=0;
- bool trovato=false;
- while(!trovato&&i<r){
- if(strcmp(t1[i].nome,nome)==0){
- trovato=true;
- pos=i;
- }
- i++;
- }
- return pos;
- }
- //MAIN.CPP
- #include <iostream> //Agenda telefonica che contenga Nome e Numero
- #include "libreria.h"
- #include <string.h>
- #include <stdlib.h>
- using namespace std;
- int main(int argc, char** argv) {
- tabella t2,t;
- persona p1;
- stringa nome;
- int r=0,scelta;
- bool esci=false;
- cout<<"--------AGENDA-------\n";
- while(!esci){
- cout<<"\nScegliere l'operazione da eseguire:\n";
- cout<<" 1- Inserimento nuovo contatto;\n";
- cout<<" 2- Stampa agenda;\n";
- cout<<" 3- Ricera contatto;\n";
- cout<<" 4- Fine programma;\n";
- cin>>scelta;
- switch(scelta){
- case 1:{
- cout<<"Inserire nome contatto: ";
- cin>>p1.nome;
- cout<<"Inserire numero contatto: ";
- cin>>p1.numero;
- letturatabella(t2,p1,r);
- break;
- }
- case 2:{
- stampa_agenda(t2,r);
- break;
- }
- case 3:{
- cout<<"Quale nome vuoi cercare? ";
- cin>>nome;
- int pos=ricerca_contatto(t2,r,nome);
- if(pos==-1)
- cout<<"Il nome cercato non e' presente nell'agenda\n";
- else
- stampa_record(t2[pos]);
- break;
- }
- case 4:{
- esci=true;
- cout<<"Fine Programma.\n";
- break;
- }
- default:
- cout<<"Fine Programma.\n";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement