Created
September 25, 2013 09:15
-
-
Save shoter/6697083 to your computer and use it in GitHub Desktop.
This file contains 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 <iostream> | |
#include <conio.h> | |
const int PRZELOT_COUNT = 4; | |
#define LINE_BREAK std::cout << "---------------------------------------------------" << std::endl; | |
//napisz progrma w ktorej zadeklarujesz tablice struktua, struktura o nazwie przelot zawiera | |
// nastepujace elementy : trasa(dokad), | |
//cena | |
//dlugosc trasy | |
//czas- w godzinach | |
//linia | |
//ustal rozmiar tablicy | |
//nastepujace operacje | |
//wczytaj z klawy | |
//wypisanie danych w estetyczny | |
//wypisanie trasy i ceny przelotow dla wszystkich linii | |
//obliczenie sredniej ceny wszystkich przelotow | |
//obliczenie ceny najdluzszego przelotu | |
//wypisanie wszystkich przelotów dluzszych niz 1000 km | |
struct Przelot | |
{ | |
char trasa[30]; | |
char linia[30]; | |
float cena; | |
float dlugosc_trasy; | |
int czas; | |
}; | |
void wypelnij_przelot(Przelot &przelot) | |
{ | |
std::cout << "Podaj trase : " << std::endl; | |
std::cin >> przelot.trasa; | |
std::cout << "Podaj linie : " << std::endl; | |
std::cin >> przelot.linia; | |
std::cout << "Podaj cene : " << std::endl; | |
std::cin >> przelot.cena; | |
std::cout << "Podaj dlugosc trasy : " << std::endl; | |
std::cin >> przelot.dlugosc_trasy; | |
std::cout << "Podaj czas lotu : " << std::endl; | |
std::cin >> przelot.czas; | |
} | |
void wypisz_przelot(const Przelot &przelot) | |
{ | |
LINE_BREAK | |
std::cout << "Przelot linii " << przelot.linia << " trasa : " << przelot.trasa << std::endl; | |
std::cout << "Cena : " << przelot.cena << ", dlugosc trasy : " << przelot.dlugosc_trasy << ", czas lotu : " << przelot.czas << std::endl; | |
LINE_BREAK | |
} | |
float srednia_cena(const Przelot *tab) | |
{ | |
float sum = 0; | |
for(int i = 0;i < PRZELOT_COUNT; i++) | |
{ | |
sum += tab->cena; | |
tab++; | |
} | |
return sum / PRZELOT_COUNT; | |
} | |
float cena_najdluzszego(const Przelot *tab) | |
{ | |
const Przelot* max = tab; | |
for(int i = 1;i < PRZELOT_COUNT; i++) | |
{ | |
if(max->dlugosc_trasy < tab->dlugosc_trasy) | |
max = tab; | |
tab++; | |
} | |
return max->cena; | |
} | |
void dlugie(const Przelot *tab) | |
{ | |
for(int i = 0;i < PRZELOT_COUNT; i++) | |
{ | |
if(tab->dlugosc_trasy > 1000) | |
wypisz_przelot(*tab); | |
tab++; | |
} | |
} | |
int main() | |
{ | |
Przelot przeloty[PRZELOT_COUNT]; | |
for(int i = 0; i < PRZELOT_COUNT; i++) | |
{ | |
wypelnij_przelot(przeloty[i]); | |
} | |
std::cout<< "TABLICA_LOTOW : " << std::endl; | |
for( int i = 0; i< PRZELOT_COUNT ; i++) | |
wypisz_przelot(przeloty[i]); | |
std::cout << std::endl << std::endl; | |
std::cout << "Srednia cena na wszystkich przelotach : " << srednia_cena(przeloty) << std::endl; | |
std::cout << "Cena najdluzszego przelotu : " << cena_najdluzszego(przeloty) << std::endl; | |
std::cout << "Loty przelotow dluzszych niz 1000km : " << std::endl; | |
dlugie(przeloty); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment