Procedural struct Human int height int age void
- Slides: 98
Παράδειγμα – Procedural struct Human { int height; int age; }; void isborn(struct Human *a. Human); void ages(struct Human *a. Human); void grows(struct Human *a. Human, int inc) main(){ struct Human peter; isborn(&peter); ages(&peter); grows(&peter, 10); } void isborn(struct Human *a. Human){ a. Human->height = 40; a. Human->age = 0; } void ages(struct Human *a. Human){ a. Human->age += 1; } void grows(struct Human *a. Human, int inc){ a. Human->height += inc; }
Παράδειγμα – OOP #include <cstdio> using namespace std; class Human { private: int height; int age; public: void Ages(); void Is. Born(); void Grows(int inc); }; void Human: : Ages(){ age += 1; // απλούστερος κώδικας !!! } void Human: : Is. Born(){ height = 40; age = 0; } void Human: : Grows(int inc){ height += inc; } int main(){ Human peter; peter. Is. Born(); peter. Ages(); peter. Grows(10); // απλούστερος κώδικας !!! }
Spaghetti υλοποίηση # include <stdio. h> # include <stdlib. h> struct Person { char * name; int age; };
int main(){ struct Person x, y; x. name = (char *) malloc (10* sizeof(char)); x. age = 0; /*. . */ strcpy (x. name, "Name 1"); printf ("%s", x. name); y. name = (char *) malloc (10* sizeof(char)); y. age = 0; /*. . */ strcpy (y. name, "Name 2"); printf ("%s", y. name); return 0; }
int main(){ struct Person x, y; x. name = (char *) malloc (10* sizeof(char)); x. age = 0; /*. . */ strcpy (x. name, "Name 1"); printf ("%s", x. name); y. name = (char *) malloc (10* sizeof(char)); y. age = 0; /*. . */ strcpy (y. name, "Name 2"); /* BOOM!!! */ printf ("%s", y. name); } return 0;
int main(){ struct Person x, y; x. name = (char *) malloc (10* sizeof(char)); x. age = 0; /*. . */ strcpy (x. name, "Name 1"); printf ("%s", x. name); y. name = (char *) malloc (10* sizeof(char)); y. age = 0; /*. . */ strcpy (y. name, "Name 2"); /* BOOM!!! */ printf ("%s", y. name); } return 0;
int main(){ struct Person x, y; x. name = (char *) malloc (10* sizeof(char)); if(x. name == NULL) {printf(“…. . ”); return 1; } x. age = 0; /*. . */ strcpy (x. name, "Name 1"); printf ("%s", x. name); y. name = (char *) malloc (10* sizeof(char)); if(y. name == NULL) {printf(“…. . ”); return 1; } y. age = 0; /*. . */ strcpy (y. name, "Name 2"); printf ("%s", y. name); } return 0;
Συνάρτηση αρχικοποίησης # include <stdio. h> struct Person { char * name; int age; }; void init(struct Person *p){ p->name = (char *) malloc (10* sizeof(char)); p->age = 0; }
int main(){ struct Person x, y; init(&x); /*. . */ strcpy (x. name, "Name 1"); printf ("%s", x. name); init(&y); /*. . */ strcpy (y. name, "Name 2"); printf ("%s", y. name); } return 0;
# include <stdio. h> struct Person { char * name; int age; }; void init(struct Person *p){ p->name = (char *) malloc (10* sizeof(char)); if (p -> name == NULL) {printf(“…. . ”); exit(1); } p->age = 0; }
int main(){ struct Person x, y; init(&x); /*. . */ strcpy (x. name, "Name 1"); printf ("%s", x. name); init(&y); /*. . */ strcpy (y. name, "Name 2"); printf ("%s", y. name); f(); } return 0;
// ορισμός μεθόδων (definition) void Person: : init(){ name = (char *) malloc (10* sizeof(char)); // τι είναι αυτό το name ? ? ? age = 0; } void Person: : set_name(char *n) { strcpy(name, n); } void Person: : set_age(int a) { age = a; // τι είναι αυτό το age ? ? ? } char *Person: : get_name() { return name; } int Person: : get_age() { return age; }
# include <cstdlib> # include <cstring> class Person { public: char * name; // πεδία – χαρακτηριστικά κλάσης int age; void init(); // μέθοδοι κλάσης void set_name(char *n); void set_age(int a); char *get_name(); int get_age(); }; μόνο αυτές οι μέθοδοι είναι ύποπτες …… !!!
void Person: : init(){ name = (char *) malloc (10* sizeof(char)); if (name == NULL) {printf(…); exit(1); } age = 0; } void Person: : set_name(char *n) { strcpy(name, n); } void Person: : set_age(int a) { age = a; } char *Person: : get_name() { return name; } int Person: : get_age() { return age; }
# include <cstdio> # include <cstdlib> # include <cstring> class Person { public: char * name; int age; void init(); void set_name(char *n); void set_age(int a); char *get_name(); int get_age(); };
int main(){ Person x, y; x. name = (char *) malloc (10* sizeof(char)); x. age = 0; /*. . */ strcpy (x. name, "Name 1"); printf ("%s", x. name); y. name = (char *) malloc (10* sizeof(char)); y. age = 0; /*. . */ strcpy (y. name, "Name 2"); printf ("%s", y. name); return 0; }
# include <cstdio> # include <cstdlib> # include <cstring> class Person { private: char * name; int age; public: void init(); void set_name(char *n); void set_age(int a); char *get_name(); int get_age(); };
int main(){ Person x, y; x. name = (char *) malloc (10* sizeof(char)); x. age = 0; /*. . */ strcpy (x. name, "Name 1"); printf ("%s", x. name); y. name = (char *) malloc (10* sizeof(char)); y. age = 0; /*. . */ strcpy (y. name, "Name 2"); printf ("%s", y. name); return 0; } προσπάθεια πρόσβασης σε private πεδία COMPILE ERRORS!!!
Υλοποίηση #include <stdio. h> void issue. New (int A[], int *size); void check. Validity(int A[], int size); void count. By. Last. Digit(int A[], int size, int B[]); void print. Numbers(int B[]);
Υλοποίηση int main(){ int A[100]; int current. Size = 0; int B[10]; issue. New(A, ¤t. Size); check. Validity(A, current. Size); count. By. Last. Digit(A, current. Size, B); print. Numbers(B); } return 0;
Υλοποίηση void issue. New (int A[], int *size){ int input; printf("Enter new number: "); scanf("%d", &input); A[*size] = input; (*size)++; }
Υλοποίηση void check. Validity(int A[], int size){ int i; int length; int temp; } for (i=0; i < size; i++){ length = 1; temp = A[i]; while(temp > 9){ temp = temp / 10; length++; } if (length != 5) { printf("Error with number in position %dn", i); return; } } printf("ALL OK!nx");
Υλοποίηση void count. By. Last. Digit(int A[], int size, int B[]){ int i; int last. Digit; for(i = 0; i < 10; i++) B[i] = 0; } for(i = 0; i < size; i++){ last. Digit = A[i] % 10; B[last. Digit]++; } void print. Numbers(int B[]){ int i; printf("Count by last digit: n"); } for (i = 0; i < 10; i++){ printf("%d: %dn", i, B[i]); }
Συντήρηση void issue. New (int A[], int *size){ int input; printf("Enter new number: "); scanf("%ld", &input); A[*size] = input; (*size)++; }
Συντήρηση void check. Validity(int A[], int size){ int i; int length; int temp; for (i=0; i < size; i++){ length = 1; temp = A[i]; while(temp > 9){ temp = temp / 10; length++; } if (length != 5) { printf("Error with number in position %dn", i); return; } } printf("ALL OK!nx"); }
void check. Validity(int A[], int size){ int i; int length; int temp; for (i=0; i < size; i++){ length = 1; temp = A[i]; while(temp > 9){ temp = temp / 10; length++; } if (length != 5) { printf("Error with number in position %dn", i); return; } } printf("ALL OK!nx"); }
Συντήρηση void check. Validity(int A[], int size){ int i; int length; int temp; for (i=0; i < size; i++){ length = 1; temp = A[i]; while(temp > 9){ temp = temp / 10; length++; } if (length != 6) { printf("Error with number in position %dn", i); return; } } printf("ALL OK!nx"); }
void count. By. Last. Digit(int A[], int size, int B[]){ int i; int last. Digit; for(i = 0; i < 10; i++) B[i] = 0; for(i = 0; i < size; i++){ last. Digit = A[i] % 10; B[last. Digit]++; } } void print. Numbers(int B[]){ int i; printf("Count by last digit: n"); for (i = 0; i < 10; i++){ printf("%d: %dn", i, B[i]); } }
Υλοποίηση #include <cstdio> class Manage. AFM{ private: int A[100]; int size; public: void init(); void issue. New(); void check. Validity(); int get. Last. Digits. And. Size(int Last. Digits[]); /* επιστρέφει το size και τα τελευταία ψηφία των Α[i] */ };
Υλοποίηση void Manage. AFM: : init(){ size = 0; } void Manage. AFM: : issue. New (){ int input; printf("Enter new number: "); scanf("%d", &input); A[size] = input; size++; }
Υλοποίηση void Manage. AFM: : check. Validity(){ int i; int length; int temp; } for (i=0; i < size; i++){ length = 1; temp = A[i]; while(temp > 9){ temp = temp / 10; length++; } if (length != 5) { printf("Error with number in position %dn", i); return; } } printf("ALL OK!nx");
Υλοποίηση int Manage. AFM: : get. Last. Digits. And. Size(int Last. Digits[]){ int i; for(i = 0; i < size; i++){ Last. Digits[i] = A[i] % 10; } return size; }
Υλοποίηση class AFMStatistics{ private: int B[10]; public: void init(); void count. By. Last. Digit(int Last. Digits[], int size); void print. Numbers(); }; void AFMStatistics: : init(){ int i; for(i = 0; i < 10; i++) B[i] = 0; }
Υλοποίηση void AFMStatistics: : count. By. Last. Digit(int Last. Digits[], int size){ int i; int last. Digit; for(i = 0; i < size; i++){ last. Digit = Last. Digits[i]; B[last. Digit]++; } } void AFMStatistics: : print. Numbers(){ int i; printf("Count by last digit: n"); for (i = 0; i < 10; i++){ printf("%d: %dn", i, B[i]); } }
int main(){ Manage. AFM manager; AFMStatistics stats; int Last. Digits[100]; int current. Size; manager. init(); manager. issue. New(); manager. check. Validity(); current. Size = manager. get. Last. Digits. And. Size(Last. Digits); stats. init(); stats. count. By. Last. Digit(Last. Digits, current. Size); stats. print. Numbers(); } return 0;
Συντήρηση - τι κερδίσαμε ? ? ? void Manage. AFM: : init(){ size = 0; } void Manage. AFM: : issue. New (){ int input; printf("Enter new number: "); scanf("%ld", &input); A[size] = input; size++; }
Συντήρηση - τι κερδίσαμε ? ? ? void Manage. AFM: : check. Validity(){ int i; int length; int temp; } for (i=0; i < size; i++){ length = 1; temp = A[i]; while(temp > 9){ temp = temp / 10; length++; } if (length != 5) { printf("Error with number in position %dn", i); return; } } printf("ALL OK!nx");
Συντήρηση - τι κερδίσαμε ? ? ? int Manage. AFM: : get. Last. Digits. And. Size (int Last. Digits[]){ int i; for(i = 0; i < size; i++){ Last. Digits[i] = A[i] % 10; } return size; }
Συντήρηση - τι κερδίσαμε ? ? ? #include <cstdio> class Manage. AFM{ private: int A[100]; int size; public: void init(); void issue. New(); void check. Validity(); int get. Last. Digits. And. Size (int Last. Digits[]); };
Συντήρηση - τι κερδίσαμε ? ? ? void AFMStatistics: : init(){ int i; for(i = 0; i < 10; i++) B[i] = 0; } void AFMStatistics: : count. By. Last. Digit (int Last. Digits[], int size){ int i; int last. Digit; } for(i = 0; i < size; i++){ last. Digit = Last. Digits[i]; B[last. Digit]++; } void AFMStatistics: : print. Numbers(){ int i; printf("Count by last digit: n"); } for (i = 0; i < 10; i++){ printf("%d: %dn", i, B[i]); }
Συντήρηση - τι κερδίσαμε ? ? ? class AFMStatistics{ private: int B[10]; public: void init(); void count. By. Last. Digit (int Last. Digits[], int size); void print. Numbers (); };
- Public void drawsquare(int x, int y, int len)
- Typedef struct tree int info
- Typedef struct tree
- Typedef struct tree int info
- Struct node int data struct node* next
- Sum0
- Void swap(int a int b)
- Int f(int n)
- Copy struct c
- Int max(int x int y)
- Interface calculator public int add class test
- Divideint
- Stone age chronology
- Iron age bronze age stone age timeline
- Typedef struct in c
- Typedef node
- Struct point int x y
- Struct node int data
- Struct node int i float j
- What are structure
- Struct point int x y
- Nodenext
- Void setup
- Void main(void)
- Void main(void)
- Lc gate height gauge
- Void main() int i j charval='j'
- Void main() int i j charval='j'
- Int ival char cval void *ptr
- Void* to int
- Void func(int num)
- Arrayint
- Public void int
- 저장 유형 지정자
- Int i=10
- Mainstring
- Void main int main
- Gcse pe pep introduction example
- Body mass indicator
- Interface myinterface int foo(int x)
- Int main(int argc, char** argv)
- 7팩토리얼
- Arduino constant int
- Int main() int num=4
- Int max
- Include
- Class person string name
- Human height normal distribution
- Bone age greater than chronological age
- Victorian age and modern age
- Paleolithic age vs neolithic age
- Neolithic period timeline
- "age of trilobites" or "age of fish".
- Brahmanas meaning
- Romantic age and victorian age
- Procedural vs substantive due process
- Procedural fairness
- Procedural abstraction examples
- Primary reliance on researcher to deal with procedural bias
- Procedural vs imperative
- Oracle procedural language extensions to sql
- A purpose of procedural writing is
- Features of a procedural text
- Blender procedural modeling
- Procedural analysis
- Types of knowledge
- Isa-88
- Procedural hukommelse
- Substantive vs procedural due process
- Dpgt samples
- Procedural python
- Joey paquet
- Examples of substantive due process
- Due process definition law
- Diagnostic and procedural coding
- Substantive vs procedural due process
- Substantive vs procedural due process
- Procedural self-knowledge includes ________.
- Chapter 19 procedural coding
- What is procedural programming
- The backward representation mapping maps from to facts.
- Procedural fluency examples
- Procedural steps in dental public health
- Compare procedural semantics and declarative semantics.
- Procedural sound generation
- Procedural constructs
- Procedural dependency adalah
- Procedural unconscionability
- Procedural knowledge examples in math
- The procedural view of democracy is most concerned with
- Ap psychology chapter 9 memory
- Physical and procedural barriers of cross contamination
- Relational algebra and calculus
- Apa pengertian dari procedural dependency?
- Antecedent procedural questions
- Blender procedural road