Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // kolokwium2rafalGrzywocz.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include<iostream>
- #include<string>
- #include<fstream>
- using namespace std;
- enum class Gatunek {HORROR, BIOGRAFIA, AKCJA, KOMEDIA, OBYCZAJOWY, THRILLER};
- // STRUKTURA FILM
- struct Film
- {
- string tytul;
- double dlugosc;
- int rokWydania;
- Gatunek gatunek;
- void drukuj();
- };
- void Film::drukuj() {
- cout << "Tytul filmu:" << this->tytul << endl << "Dlugosc:" << this->dlugosc << endl << "Rok wydania:" << this->rokWydania << endl;
- }
- Film stworzFilm() {
- Film film;
- cout << "Tworzenie nowego filmu\n Podaj nazwe:";
- cin >> film.tytul;
- cout << "Podaj dlugosc filmu:";
- cin >> film.dlugosc;
- cout << "Podaj rok wydania:";
- cin >> film.rokWydania;
- int x;
- cout << "Wybierz typ" << endl;
- cout << "0.HORROR" << endl;
- cout << "1.BIOGRAFIA" << endl;
- cout << "2.AKCJA" << endl;
- cout << "3.KOMEDIA" << endl;
- cout << "4.OBYCZAJOWY" << endl;
- cout << "5.THRILLER" << endl;
- cin >> x;
- switch (x){
- case 0: film.gatunek = Gatunek::HORROR;
- break;
- case 1:film.gatunek = Gatunek::BIOGRAFIA;
- break;
- case 2:film.gatunek = Gatunek::AKCJA;
- break;
- case 3:film.gatunek = Gatunek::KOMEDIA;
- break;
- case 4:film.gatunek = Gatunek::OBYCZAJOWY;
- break;
- case 5:film.gatunek = Gatunek::THRILLER;
- break;
- default:
- break;
- }
- return film;
- }
- double calkaP(double(*f)(double x), double a, double b, int n, string nazwaPliku) {
- ofstream calkaFile;
- calkaFile.open(nazwaPliku);
- calkaFile << "Calka na przedziale [" << a << ", " << b << "]\n";
- calkaFile << "liczba prostokatow: " << n << "\n";
- double* tabela = new double[n + 1];
- double x = a;
- for (int i = 0; i <=n; i++) {
- tabela[i] = x;
- x += (b - a) / n;
- }
- double calka = 0;
- for (int i = 1; i <= n; i++) {
- calka += f(tabela[i])*(b - a) / n;
- }
- calkaFile << "wartosc calki: " << calka;
- calkaFile.close();
- return calka;
- }
- double kwadratowa(double x) {
- return x*x;
- }
- int main()
- {
- Film* czteryFilmy = new Film[4];
- for (int i = 0; i < 4; i++) {
- czteryFilmy[i] = stworzFilm();
- }
- for (int i = 0; i < 4; i++) {
- czteryFilmy[i].drukuj();
- }
- ofstream myFile;
- myFile.open("film.txt");
- myFile << czteryFilmy[0].tytul << ",\n" << czteryFilmy[0].dlugosc << ",\n" << czteryFilmy[0].rokWydania;
- calkaP(kwadratowa, 0, 3, 10, "plikZCalka.txt");
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement