Last active
August 29, 2015 14:12
-
-
Save eroltutumlu/d66c8939627457f42b30 to your computer and use it in GitHub Desktop.
Struct kullanımına ufak bir örnek
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| #define SIZE 2 | |
| enum boolean{ | |
| false=0, | |
| true | |
| }isTrue; | |
| typedef enum boolean bool; | |
| struct StudentData{ | |
| char name[30]; | |
| struct{ | |
| int midtermExam; | |
| int finalExam; | |
| int average; | |
| char status[5]; | |
| }Information; | |
| }; | |
| int i,j; | |
| void showStudentStatus(struct StudentData *Students); | |
| int Control(int examNot); | |
| struct StudentData Student[SIZE]; | |
| void NotlaraGoreSirala(); | |
| int main(void) { | |
| int loopIndex=0; | |
| for(loopIndex=0;loopIndex<SIZE;loopIndex++) | |
| { | |
| printf("Ogrenci adi: "); | |
| scanf("%s",&Student[loopIndex].name); | |
| int k=0; | |
| while(k!=2) | |
| { | |
| printf("Ogrencinin vize notu: "); | |
| scanf("%d",&Student[loopIndex].Information.midtermExam); | |
| if(Control(Student[loopIndex].Information.midtermExam)==true) | |
| { | |
| k++; | |
| } | |
| else | |
| { | |
| printf("0-100 arasi bir deger olmalidir.\n"); | |
| continue; | |
| } | |
| printf("Ogrencinin final notu: "); | |
| scanf("%d",&Student[loopIndex].Information.finalExam); | |
| if(Control(Student[loopIndex].Information.finalExam)==true) | |
| { | |
| k++; | |
| } | |
| else | |
| { | |
| printf("0-100 arasi bir deger olmalidir.\n"); | |
| while(Control(Student[loopIndex].Information.finalExam)!=1) | |
| { | |
| printf("Ogrencinin final notu: "); | |
| scanf("%d",&Student[loopIndex].Information.finalExam); | |
| } | |
| k++; | |
| } | |
| } | |
| Student[loopIndex].Information.average=Student[loopIndex].Information.finalExam*0.6+Student[loopIndex].Information.midtermExam*0.4; | |
| if(Student[loopIndex].Information.average<60) | |
| strncpy(Student[loopIndex].Information.status,"Kaldi\0",6); | |
| else | |
| strncpy(Student[loopIndex].Information.status,"Gecti\0",6); | |
| } | |
| showStudentStatus(Student); | |
| getch(); | |
| return 0; | |
| } | |
| int Control(int examNot) | |
| { | |
| if(examNot>=0 && examNot <=100) | |
| return 1; | |
| else | |
| return 0; | |
| } | |
| void showStudentStatus(struct StudentData *Students) | |
| { | |
| printf("Ogrenci Adi"); | |
| printf("\tVize Notu"); | |
| printf("\tFinal Notu"); | |
| printf("\tOrtalama"); | |
| printf("\tDurum\n"); | |
| NotlaraGoreSirala(); | |
| for(i=0;i<SIZE;i++) | |
| { | |
| printf("%12s",Students[i].name); | |
| printf("%12d",Students[i].Information.midtermExam); | |
| printf("%15d",Students[i].Information.finalExam); | |
| printf("%10d",Students[i].Information.average); | |
| printf("%18s",Students[i].Information.status); | |
| printf("\n"); | |
| } | |
| } | |
| void NotlaraGoreSirala() | |
| { | |
| struct StudentData student; | |
| for(i=0;i<SIZE-1;i++) | |
| { | |
| for(j=0;j<SIZE-i-1;j++) | |
| { | |
| if(Student[j+1].Information.average >Student[j].Information.average) | |
| { | |
| student = Student[j]; | |
| Student[j] = Student[j+1]; | |
| Student[j+1] = student; | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment