Προς το περιεχόμενο

Βοηθεια για ασκηση σε τει


dimitrispa

Προτεινόμενες αναρτήσεις

Δημοσ.

>#include <stdio.h>
#include <stdlib.h>
#include<time.h>
#include <string.h>
# define arithmos 1000 

char file1[30]="foithtes.txt";
char file2[30]="thlefona.txt";

struct student{
      int AM;
      char *FName;
      char *LName;
      int Year;
      struct student *next;
};    
  
struct studphone{
      int AM;
      int *phoneNumber;
      struct studphone *next;
};       

struct list{
struct student *head;
int elements;
};
struct Newlist{
struct studphone *head;
int number;
};

void initlist(struct list *L){
L->head=NULL;
L->elements=0;
}

void initnewlist(struct Newlist *L){
L->head=NULL;
L->number=0;
}


int insertAtHead(struct list *L, int AM, int Year, char Last[11], char First[11]){

struct student *stud; 
stud =(struct student*) malloc(sizeof(struct student));

   
if (L->head==NULL){		
	L->head=stud;
       stud->next=NULL;
       stud->Year=Year;
       (*stud).AM=AM;
       stud->LName=Last;
       stud->FName=First;
}
else{
	stud->next=L->head;
	L->head=stud;
	stud->Year=Year;
       (*stud).AM=AM;
       stud->LName=Last;
       stud->FName=First;
}
   L->elements++;
return 1; 
}

int insertAtNewHead(struct Newlist *L, int MyAM, int MyPhoneNumber[11]){

struct studphone *stud; 
stud =(struct studphone*) malloc(sizeof(struct studphone));

   
if (L->head==NULL){		
	L->head=stud;
       stud->next=NULL;
       (*stud).AM=MyAM;
       stud->phoneNumber=MyPhoneNumber;
}
else{
	stud->next=L->head;
	L->head=stud;
	(*stud).AM=MyAM;
       stud->phoneNumber=MyPhoneNumber;
}
   L->number++;
return 1; 
}

int deleteFromHead(struct list *L){
struct student *cur;

if(L->head==NULL){
	return 0;
}

cur=L->head;
L->head=L->head->next;
free(cur);
L->elements--;
printf("diagrafh enos stoixeiou.\n");
return 1;
}

int deleteAtNewHead(struct Newlist *T){
struct studphone *cur;
for(int i=0;i<3;i++){
if(T->head==NULL){
	return 0;
}

cur=T->head;
T->head=T->head->next;
free(cur);
T->number--;
printf("diagrafh enos stoixeiou.\n");

}
return 1;
}

int deleteAM(struct list *L,struct Newlist *T,int wantedAM){ 

   struct student *cur1, *previous1;
struct studphone *cur2, *previous2;

   cur1=L->head;
cur2=T->head;

   if(cur1->AM == wantedAM){

          printf("diagrafh 1ou stoixeiou. \n");    
          deleteFromHead(L); 
          deleteAtNewHead(T);
	   return 1;   
   }   
   else
   {
		previous1=cur1;   
            cur1=cur1->next;
            previous2=cur2;   
            cur2=cur2->next;

            while(cur1!=NULL){
			 
                  if(cur1->AM ==wantedAM){
			
				   free(cur1);

				   previous1->next = cur1->next;
                       
                       
					for(int i=0;i<3;i++){
						free(cur2);
						previous2->next = cur2->next;
						
					}     
                             return 1;
                   }
                     else
                     { 
                         previous1 = previous1->next;
                         cur1 = cur1->next;
					  
					  for(int i=0;i<3;i++){

					  previous1 = previous1->next;
                         cur1 = cur1->next;
                     
					  }   
				  }        
               } 
              return 0;  
     } 
} 

int findLastName(struct list *L,struct Newlist *T,char *Last)
{	
struct studphone *cur2;
   struct student *cur1;
   int equal = 1;

   if(L->head==NULL){ 
	printf("h lista einai adeia.\n"); return 0;
   }

   else 
	cur1 = L->head; 
	cur2 = T->head;
while(cur1!=NULL){ 
        
	if(strcoll(cur1->LName,Last) == 0){ 
			
		for(int i=0;i<3;i++){
			printf("To %d thlefono tou foithth me onoma %s einai to :%d\n", i, cur1->LName, cur2->phoneNumber);
			cur2=cur2->next;
		}
           
		return 0;
	}
          
	else 
		cur1 = cur1->next;
		cur2 = cur2->next;
    }

    printf("den vre8hke foithths me auto to teleutaio onoma.\n");
    return -1; 
}

int thlefonasearch(struct list *S,struct Newlist *T){

int i;
struct student *cur1;
struct studphone *cur2;

cur1=S->head;
cur2=T->head;

while(cur1!=NULL){
	
	if(cur1->Year==2006){

		for(i=0;i<3;i++){
			printf("To %d thlefono tou foithth me am %d einai to :%d\n", i, cur2->AM, cur2->phoneNumber);
			cur2=cur2->next;
		}
	}
	else{
		cur1=cur1->next;
		for(i=0;i<3;i++){
			cur2=cur2->next;
		}

	}
}
return 0;
}

int menu(void){
printf("1:delete polaplasia tou 10\n");
printf("2:bres ta thlefona toy foithth me eponimo\n");
printf("3:bres ta thlefona me etos egrafhs\n");
return 0;
}

int main(void){

char name[10],lastname[10];
int i,j,w,del,k,g,etosegrafhs,AM,thl[10],choise;
FILE *stud, *phones;
static const char *AB = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";


srand(time(NULL));

stud=fopen(file1,"wt");

for(i=0;i<arithmos;i++){

AM=i;
etosegrafhs=1990+rand()%18;

for(w=0;w<10;w++){
	
	name[w] = AB[rand() % (strlen(AB)-1)];
	lastname[w] = AB[rand() % (strlen(AB)-1)];

}
name[w] ='\0';
lastname[w]='\0';

fprintf(stud,"%d %s %s %d \n", AM, name, lastname, etosegrafhs);

}
   fclose(stud);



phones=fopen(file2,"wt");

for(i=0;i<arithmos;i++){
	
	for(j=0;j<3;j++){
	
		AM=i;
		fprintf(phones,"%d ", AM);

		for(w=0;w<10;w++){
		
			thl[w]=rand()%10;
		

		}
		thl[w]='\0';
		for(w=0;w<11;w++){
			fprintf(phones,"%d", thl[w]);
		}
		fprintf(phones," \n");

	}
}
fclose(phones);


	struct list *MyList;
	MyList=(struct list*) malloc(sizeof(struct list));
       
	initlist(MyList);



       if ((stud  = fopen(file1, "r"))==NULL){

                 printf("de mporei na anoiksei to arxeio student.txt\n"); exit(1);
                 
       }
	
       else{ 
		
       struct student *tempstud;
       tempstud=(struct student*) malloc(sizeof(struct student));

       
	int eggrafes = 0;
 
	while(!feof(stud) && eggrafes < 1000){

           eggrafes++;           
           fscanf(stud, "%d %s %s %d", &AM, &name, &lastname, &etosegrafhs);
           insertAtHead(MyList, AM, etosegrafhs, name, lastname);
       }
         	

       }
      
	struct Newlist *PhoneList;

	PhoneList=(struct Newlist*) malloc(sizeof(struct Newlist));

	initnewlist(PhoneList);

       if ((phones = fopen(file2, "r"))==NULL){
                
		printf("de mporei na anoiksei to arxeio phones.txt\n"); exit(1);
                 
       }     
       else{    

            struct studphone *tempphone;
            tempphone=(struct studphone*) malloc(sizeof(struct studphone));

           if(tempphone==NULL){ 
			
			printf("h mnimi den eparkei . exit \n"); 
			return 0;
		
		}

           while(!feof(phones)){

                 fscanf(phones, "%d", &tempphone->AM); 

			for(k = 0; k < 3; k++){  

				for( g = 0; g < 10; g++){

					if(g%10 == 0 && g!=0){

						fscanf(phones, "%d", &tempphone->phoneNumber[g]);
					}
				}    
			}      

			insertAtNewHead(PhoneList, tempphone->AM,tempphone->phoneNumber);
                  
           }

         
	}
         menu();
	  scanf("%d", &choise);

	  if(choise==1){
        
		  for (del = 0; del < 1000; del++){
		  
			  if( del%10 == 0){
			  
				  if(deleteAM(MyList,PhoneList,del)==1){
				
					  printf("o foithths me AM %d diagrafhke.\n", del);
			 				
				  }
				   
				  else
								
					  printf("de vrethike foithths me auto to AM.\n");  
		
			  }

	 
		  }
	  }

else if(choise==2){
         printf("\n dokimazoume ena onoma pou den uparxei:\n");

         findLastName(MyList,PhoneList,"aaa");

         printf("dokimazoume ena onoma pou uparxei.\n");



         fscanf(stud, "%d %s %s %d", &AM, &name, &lastname, &etosegrafhs);
         
         findLastName(MyList,PhoneList,lastname);
}

/*else if(choise==3){
      thlefonasearch(MyList,PhoneList);
}*/
         fclose(stud);

	  printf("to arxeio stud ekleise.\n");

         fclose(phones);

         printf("to arxeio phones ekleise.\n");

	system("pause");
return 0;
}



η εκφωνιση ειναι η εξεισ:

Φτιάξτε την ακόλουθη εφαρμογή. Δημιουργήστε σε αρχείο 1000 Φοιτητές(ΑΜ, όνομα, επμο, έτος_εγγραφής). Τα ΑΜ θα είναι διαδοχικά (1, 2, 3, κλπ.), το όνομα και το επμο θα είναι random char[10] και το έτος random από 1990-2007. Δημιουργήστε σε αρχείο 3000 εγγραφές Τηλνα(ΑΜ, αριθμός_τηλ) και βάλτε κάθε φοιτητή να έχει 3 τηλέφωνα (τυχαίοι int[10]). Φορτώστε τους φοιτητές και τα τηλνα σε δύο ξεχωριστές απλά συνδεδεμένες λίστες. Απαντήστε στα ακόλουθα ερωτήματα.

- Σβήστε από τις δομές τις εγγραφές των φοιτητών και τηλ/νων που αντιστοιχούν σε ΑΜ που είναι πολλαπλάσια του 10.

- Βρες τα τηλνα του φοιτητή με επμο=..(κάποιο επμο που υπάρχει και κάποιο που δεν υπάρχει)

- Βρες τα τηλνα των φοιτητών με έτος εγγραφής 2006.

 

η διορια παραδοσης ειναι μεχρι και 18/05/08 για το λογο αυτο χρειαζομαι αμεση βοηθεια....

Δημοσ.
Kάνε attach και τα txt sample files που έχεις σε περίπτωση που κάποιος αποφασίσει να σε βοηθήσει.

 

το deadline του εχει περασει ετσι και αλλιως

αφου εκανε ποστ 1 μερα πριν την ημερομηνια παραδοσης....:rolleyes:

Αρχειοθετημένο

Αυτό το θέμα έχει αρχειοθετηθεί και είναι κλειστό για περαιτέρω απαντήσεις.

  • Δημιουργία νέου...