Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.39 KB | None | 0 0
  1. // kolokwium2rafalGrzywocz.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include<iostream>
  6. #include<string>
  7. #include<fstream>
  8. using namespace std;
  9.  
  10. enum class Gatunek {HORROR, BIOGRAFIA, AKCJA, KOMEDIA, OBYCZAJOWY, THRILLER};
  11. // STRUKTURA FILM
  12. struct Film
  13. {
  14. string tytul;
  15. double dlugosc;
  16. int rokWydania;
  17. Gatunek gatunek;
  18. void drukuj();
  19. };
  20.  
  21. void Film::drukuj() {
  22.     cout << "Tytul filmu:" << this->tytul << endl << "Dlugosc:" << this->dlugosc << endl << "Rok wydania:" << this->rokWydania << endl;
  23. }
  24. Film stworzFilm() {
  25.     Film film;
  26.     cout << "Tworzenie nowego filmu\n Podaj nazwe:";
  27.     cin >> film.tytul;
  28.     cout << "Podaj dlugosc filmu:";
  29.     cin >> film.dlugosc;
  30.     cout << "Podaj rok wydania:";
  31.     cin >> film.rokWydania;
  32.     int x;
  33.     cout << "Wybierz typ" << endl;
  34.     cout << "0.HORROR" << endl;
  35.     cout << "1.BIOGRAFIA" << endl;
  36.     cout << "2.AKCJA" << endl;
  37.     cout << "3.KOMEDIA" << endl;
  38.     cout << "4.OBYCZAJOWY" << endl;
  39.     cout << "5.THRILLER" << endl;
  40.     cin >> x;
  41.     switch (x){
  42.         case 0: film.gatunek = Gatunek::HORROR;
  43.             break;
  44.         case 1:film.gatunek = Gatunek::BIOGRAFIA;
  45.             break;
  46.         case 2:film.gatunek = Gatunek::AKCJA;
  47.             break;
  48.         case 3:film.gatunek = Gatunek::KOMEDIA;
  49.             break;
  50.         case 4:film.gatunek = Gatunek::OBYCZAJOWY;
  51.             break;
  52.         case 5:film.gatunek = Gatunek::THRILLER;
  53.             break;
  54.     default:
  55.         break;
  56.     }
  57.     return film;
  58. }
  59. double calkaP(double(*f)(double x), double a, double b, int n, string nazwaPliku) {
  60.     ofstream calkaFile;
  61.     calkaFile.open(nazwaPliku);
  62.     calkaFile << "Calka na przedziale [" << a << ", " << b << "]\n";
  63.     calkaFile << "liczba prostokatow: " << n << "\n";
  64.     double* tabela = new double[n + 1];
  65.     double x = a;
  66.     for (int i = 0; i <=n; i++) {
  67.         tabela[i] = x;
  68.         x += (b - a) / n;  
  69.     }
  70.     double calka = 0;
  71.     for (int i = 1; i <= n; i++) {
  72.         calka += f(tabela[i])*(b - a) / n;
  73.     }
  74.     calkaFile << "wartosc calki: " << calka;
  75.     calkaFile.close();
  76.     return calka;
  77. }
  78. double kwadratowa(double x) {
  79.     return x*x;
  80. }
  81. int main()
  82. {
  83.     Film* czteryFilmy = new Film[4];
  84.     for (int i = 0; i < 4; i++) {
  85.         czteryFilmy[i] = stworzFilm(); 
  86.     }
  87.     for (int i = 0; i < 4; i++) {
  88.         czteryFilmy[i].drukuj();
  89.     }
  90.     ofstream myFile;
  91.     myFile.open("film.txt");
  92.     myFile << czteryFilmy[0].tytul << ",\n" << czteryFilmy[0].dlugosc << ",\n" << czteryFilmy[0].rokWydania;
  93.     calkaP(kwadratowa, 0, 3, 10, "plikZCalka.txt");
  94.     system("pause");
  95.     return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement