tambo2199

OOP with c language

Jan 27th, 2021
694
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <stdio.h>
  3.  
  4. #define LEN 50
  5. #define N 2
  6.  
  7. typedef struct Persona
  8. {
  9.     char nome[LEN + 1];
  10.     int eta;
  11. }Persona;
  12.  
  13.  
  14. #pragma warning(disable : 4996)
  15. void Create(Persona* p, char nome[], int eta);
  16. char* GetNome(Persona *p);
  17. int GetEta(Persona *p);
  18. void SetNome(Persona *p, char nome[]);
  19. void SetEta(Persona* p, int eta);
  20. void Stampa(Persona* p);
  21. int main()
  22. {
  23.     Persona* pe;
  24.     pe = (Persona*)malloc(sizeof(Persona));
  25.  
  26.     Create(pe, (char*)"simone", 22);
  27.  
  28.     Stampa(pe);
  29.  
  30.     SetNome(pe, (char*)"martina");
  31.     SetEta(pe, 45);
  32.  
  33.     Stampa(pe);
  34.  
  35.     printf("il nome attuale della persona e' %s\n", GetNome(pe));
  36.     system("pause");
  37.     return 0;
  38. }
  39.  
  40. char* GetNome(Persona *pe)
  41. {
  42.     return pe->nome;
  43. }
  44.  
  45. int GetEta(Persona *p)
  46. {
  47.     return p->eta;
  48. }
  49.  
  50. void SetNome(Persona *p, char nome[])
  51. {
  52.     strcpy(p->nome, nome);
  53. }
  54.  
  55. void SetEta(Persona* p, int eta)
  56. {
  57.     p->eta = eta;
  58. }
  59.  
  60. void Create(Persona* p, char nome[], int eta)
  61. {
  62.     strcpy(p->nome, nome);
  63.     p->eta = eta;
  64. }
  65.  
  66. void Stampa(Persona* p)
  67. {
  68.     printf("nome: %s, eta: %d\n", p->nome, p->eta);
  69. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×