fork download
  1. // Lab 8, Working with structs
  2. // Programmer : Maiar Khattab
  3. // Editor(s) used : Code Blocks 13.12
  4. // Compiler(s) used : Code Blocks 13.12
  5.  
  6. #include<iostream>
  7. using std::cout;
  8. using std::endl;
  9.  
  10. #include<cstdlib>
  11.  
  12. //struct def
  13. struct tod
  14. {
  15. int hour;// the hr , 0-23
  16. int minute;// the min, 0-59
  17. int second;//the sec, 0-59
  18. char descr [32];//the description of the time of day
  19.  
  20. };
  21. //void printTod(const tod&);
  22. int main ()
  23. {
  24. cout << "Lab 8, Working With structs\n";
  25. cout << "Programmer: Maiar Khattab\n";
  26. cout << "Editor(s) used: Code Blocks 13.12\n";
  27. cout << "Compiler(s) used: Code Blocks 13.12\n";
  28. cout << "File: " << __FILE__ << endl;
  29. cout << "Complied: " << __DATE__ << " at " << __TIME__ << endl << endl;
  30.  
  31. tod theTime[] = {{12,0,0, "noon"},
  32. {0,0,0," midnight"},
  33. {6,00,00," supper "},
  34. {11,30,0,"bedtime"}};
  35.  
  36. for(int i; i <5; i++)
  37. {
  38. char descr [32];
  39. cout << theTime[i].descr << " is " << theTime[i].hour << ':'
  40. << theTime[i].minute << ":" << theTime[i].second << endl;
  41. }
  42. }
  43.  
  44.  
Success #stdin #stdout 0s 5284KB
stdin
#include <stdio.h>
#include <stdlib.h>

#define MAX_NUMBERS 50

void kataxorisiArithmon(int *pinakas, int *megethos) {
    printf("Eisagete mexri %d arithmous (eisagete -1 gia na termatisete tin kataxorisi) :\n", MAX_NUMBERS);
    *megethos = 0;
    int arithmos;
    while (*megethos < MAX_NUMBERS && scanf("%d", &arithmos) && arithmos != -1) {
        pinakas[(*megethos)++] = arithmos;
    }
}

void evresiMegistonKaiElaxon(int *pinakas, int megethos) {
    if (megethos == 0) {
        printf("Den kataxorithe kanenas arithmos.\n");
        return;
    }
    int megistos = pinakas[0], elaxistos = pinakas[0];
    for (int i = 1; i < megethos; i++) {
        if (pinakas[i] > megistos) megistos = pinakas[i];
        if (pinakas[i] < elaxistos) elaxistos = pinakas[i];
    }
    printf("O megalyteros arithmos einai %d.\n", megistos);
    printf("O mikroteros arithmos einai %d.\n", elaxistos);
}

float ypologismosMesouOrou(int *pinakas, int megethos) {
    int athroisma = 0;
    for (int i = 0; i < megethos; i++) athroisma += pinakas[i];
    return megethos ? (float)athroisma / megethos : 0;
}

int sygkrisi(const void *a, const void *b) {
    return (*(int*)a - *(int*)b);
}

float ypologismosMesisTimis(int *pinakas, int megethos) {
    if (megethos == 0) return 0;
    qsort(pinakas, megethos, sizeof(int), sygkrisi);
    return megethos % 2 == 0 ? (pinakas[megethos / 2 - 1] + pinakas[megethos / 2]) / 2.0 : pinakas[megethos / 2];
}

void dimiourgiaListasPollaplasion(int *pinakas, int megethos, int pollaplasio) {
    if (megethos == 0) {
        printf("Den kataxorithe kanenas arithmos.\n");
        return;
    }
    printf("Pollaplasia tou %d : ", pollaplasio);
    int vrethike = 0;
    for (int i = 0; i < megethos; i++) {
        if (pinakas[i] % pollaplasio == 0) {
            printf("%d ", pinakas[i]);
            vrethike = 1;
        }
    }
    if (!vrethike) printf("Den yparchoun pollaplasia tou %d sti lista.\n", pollaplasio);
    else printf("\n");
}

int main() {
    int pinakas[MAX_NUMBERS], megethos = 0, pollaplasio;
    char entoli;
    printf("Kalos irthate ston diaxeiristi arithmon!\n");
    while (1) {
        printf("\nEpiloges:\n1. Kataxorisi arithmon\n2. Evresi tou megaliterou kai tou mikroterou arithmou\n3. Ypologismos mesou orou kai mesis timis\n4. Dimiourgia neas listas pollaplasion\n5. Exodos apo to programma\nEisagete tin epilogi sas: ");
        scanf(" %c", &entoli);
        if (entoli == '1') kataxorisiArithmon(pinakas, &megethos);
        else if (entoli == '2') evresiMegistonKaiElaxon(pinakas, megethos);
        else if (entoli == '3') {
            printf("O mesos oros einai %.2f\n", ypologismosMesouOrou(pinakas, megethos));
            printf("I mesi timi einai %.2f\n", ypologismosMesisTimis(pinakas, megethos));
        }
        else if (entoli == '4') {
            printf("Eisagete ton arithmo gia na vreite ta pollaplasia tou: ");
            scanf("%d", &pollaplasio);
            dimiourgiaListasPollaplasion(pinakas, megethos, pollaplasio);
        }
        else if (entoli == '5') {
            printf("Antio!\n");
            break;
        }
        else {
            printf("Agnosti entoli. Parakalo dokimaste xana.\n");
        }
    }
    return 0;
}
stdout
Lab 8, Working With structs
Programmer: Maiar Khattab
Editor(s) used: Code Blocks 13.12
Compiler(s) used: Code Blocks 13.12
File: prog.cpp
Complied: Jan  8 2025 at 12:52:57

noon is 12:0:0
 midnight is 0:0:0
 supper  is 6:0:0
bedtime is 11:30:0
�S�� ��(� is 1673624904:32766:-1393935616