Created
November 25, 2015 11:58
-
-
Save huseyin/2d15f98a15c51ddd2010 to your computer and use it in GitHub Desktop.
Java sınav sorusunun C'leştirilmiş hali
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> | |
struct pdata | |
{ | |
char* student; | |
int mathematics; | |
int sciences; | |
int linguistics; | |
}; | |
struct pdata* | |
setarguments (char* people, int p1, int p2, int p3) | |
{ | |
struct pdata* pd = malloc(sizeof(struct pdata)); | |
// Veri yapısının, değişkenlerinin değerlerini set et. | |
pd->student = people; | |
pd->mathematics = p1; | |
pd->sciences = p2; | |
pd->linguistics = p3; | |
return pd; | |
} | |
// Bir çöpçü şart! | |
void | |
destroy(struct pdata* pd) | |
{ | |
free(pd); | |
} | |
// Notların ortalamasını döndür. | |
int | |
getaverage(struct pdata* pd) | |
{ | |
int avr = (pd->mathematics + pd->sciences + pd->linguistics) / 3; | |
return avr; | |
} | |
// Not geçerli bir not mu? | |
int | |
isvalid(struct pdata* pd) | |
{ | |
return (getaverage(pd) > 49) ? 1 : 0; | |
} | |
// Notu harflendir. | |
int | |
getletter(struct pdata* pd) | |
{ | |
int avr = getaverage(pd); | |
if (avr > 49 && avr < 70) | |
return 'C'; | |
else if (avr > 69 && avr < 85) | |
return 'B'; | |
else if (avr > 84 && avr <= 100) | |
return 'A'; | |
else | |
return 'F'; | |
} | |
// Bir nevi test kodu olsun. Uğraşma, sadece tek değer | |
// test et. | |
int | |
main(void) | |
{ | |
struct pdata* this = setarguments("Hüseyin", 12, 61, 45); | |
if (isvalid(this)) | |
{ | |
printf("%s: geçme notu: %c\n", this->student, getletter(this)); | |
destroy(this); | |
return 0; | |
} | |
else | |
{ | |
fprintf(stderr, "%s: geçemedi\n", this->student); | |
destroy(this); | |
return 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment