Advertisement
pieniakoskar

Zima

Mar 19th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.56 KB | None | 0 0
  1. #ifndef wyswietlanie_h
  2. #define wyswietlanie_h
  3.  
  4. #include <iostream>
  5. #include <vector>
  6. #include <string>
  7.  
  8. namespace show
  9. {
  10.  
  11. void Wpis(std::vector<std::string>zPliku); // wszystkie wpisy
  12. void Wpis(std::vector<std::string>zPliku, int ktory); // konkretny wpis
  13. void Wpis(std::vector<std::string>zPliku, int zakresOd, int zakresDo); // zakres wpisow
  14.  
  15. };
  16.  
  17. #endif
  18.  
  19.  
  20. wyswietlanie.cpp
  21.  
  22. #include "wyswietlanie.h"
  23. #include <iostream>
  24. #include <vector>
  25. #include <windows.h>
  26.  
  27. namespace show
  28. {
  29.  
  30. void Wpis(std::vector<std::string>zPliku, int ktory)
  31. {
  32. HANDLE uchwyt;
  33. uchwyt = GetStdHandle(STD_OUTPUT_HANDLE);
  34. if((ktory < 0) || (ktory-1 > zPliku.size()))
  35. {
  36. SetConsoleTextAttribute(uchwyt, 4 | FOREGROUND_INTENSITY);
  37. std::cout << "Nie ma podanego wpisu w bazie!";
  38. SetConsoleTextAttribute(uchwyt, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
  39. }
  40. else
  41. {
  42. SetConsoleTextAttribute(uchwyt, 14);
  43. std::cout << "\n" << ktory << ". " <<zPliku[ktory-1];
  44. SetConsoleTextAttribute(uchwyt, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
  45. }
  46. }
  47.  
  48. void Wpis(std::vector<std::string>zPliku, int zakresOd, int zakresDo)
  49. {
  50. if(zakresOd<1) zakresOd=1;
  51. if(zakresDo>zPliku.size()) zakresDo=zPliku.size();
  52. for(unsigned int licznik=zakresOd-1; licznik<zakresDo; licznik++)
  53. std::cout << licznik+1 << ". " << zPliku[licznik];
  54. }
  55.  
  56. void Wpis(std::vector<std::string>zPliku)
  57. {
  58. unsigned int i=0;
  59. unsigned int rozmiar = zPliku.size();
  60.  
  61. std::cout << "\n\nWszystkie wpisy:\n\n";
  62. for(i=0; i<rozmiar; i++)
  63. {
  64. std::cout << i+1 << ". " << zPliku[i];
  65. }
  66. }
  67.  
  68. };
  69.  
  70.  
  71. wczytanie.h
  72.  
  73. #ifndef wczytanie_h
  74. #define wczytanie_h
  75.  
  76. #include <vector>
  77. #include <iostream>
  78.  
  79.  
  80.  
  81. namespace get
  82. {
  83. extern std::vector<std::string>zPliku;
  84. int plik();
  85.  
  86. };
  87.  
  88. #endif
  89.  
  90.  
  91. wczytanie.cpp
  92.  
  93. #include "wczytanie.h"
  94. #include <stdio.h>
  95. #include <string>
  96. #include <iostream>
  97.  
  98. namespace get
  99. {
  100.  
  101. std::vector<std::string> zPliku;
  102. int plik()
  103. {
  104. char bufor[30]={0};
  105. int ilosc = 0;
  106. FILE *fp = NULL;
  107. if(!(fp=fopen("data.txt", "r"))) fp=fopen("data.txt", "w");
  108. while(!feof(fp))
  109. {
  110. fgets(bufor, 20, fp);
  111. zPliku.push_back(bufor);
  112. }
  113. fclose(fp);
  114. ilosc = zPliku.size();
  115. return ilosc;
  116. }
  117.  
  118. };
  119.  
  120.  
  121. snow.h
  122.  
  123. #ifndef SNOW_H
  124. #define SNOW_H
  125.  
  126. #include "stdafx.h"
  127. #include <vector>
  128. #include <string>
  129. #include <conio.h>
  130. #include <iostream>
  131. #include <stdio.h>
  132. #include <windows.h>
  133. #include "wyswietlanie.h"
  134. #include "wczytanie.h"
  135.  
  136. #define FR FOREGROUND_RED | FOREGROUND_INTENSITY
  137. #define FW FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY
  138. #define BW BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE
  139. #define B0 0
  140.  
  141. void MenuShow (std::vector<std::string>, int, HANDLE);
  142.  
  143. #endif
  144.  
  145.  
  146. snow.cpp
  147.  
  148. #include "snow.h"
  149.  
  150. int _tmain(int argc, _TCHAR* argv[])
  151. {
  152. int ileWpisow = get::plik();
  153. char x;
  154. int ktoryWpis;
  155. HANDLE hOut;
  156. CONSOLE_CURSOR_INFO ConCurInf;
  157. hOut = GetStdHandle(STD_OUTPUT_HANDLE);
  158.  
  159. ConCurInf.dwSize = 100;
  160. ConCurInf.bVisible = FALSE;
  161. SetConsoleCursorInfo(hOut, &ConCurInf);
  162.  
  163. unsigned int menu_Select = 0;
  164. bool menu_Semafor = 1;
  165. std::vector<std::string>menu;
  166. menu.push_back("Wyswietl konkretny wpis");
  167. menu.push_back("Wyswietl zakres wpisow");
  168. menu.push_back("Wyswietl wszystkie wpisy");
  169. menu.push_back("Wyswietl 10 ostatnich wpisow");
  170. menu.push_back("Zakoncz program");
  171. while(1) {
  172. if(menu_Semafor) MenuShow(menu, menu_Select, hOut);
  173. SetConsoleTextAttribute(hOut, 43);
  174. std::cout <<"Wpisow w bazie: " << ileWpisow << "\n";
  175. menu_Semafor=1;
  176. switch(x=_getch())
  177. {
  178. case 80:
  179. case 77:
  180. if(menu_Select < (menu.size()-1)) menu_Select++;
  181. break;
  182. case 72:
  183. case 75:
  184. if(menu_Select > 0) menu_Select--;
  185. break;
  186. case '2':
  187. menu_Semafor=0;
  188. MenuShow(menu, menu_Select, hOut);
  189. std::cout << "Wybrano pozycje 2." << std::endl;
  190. break;
  191. case 13:
  192. menu_Semafor=0;
  193. MenuShow(menu, menu_Select, hOut);
  194. switch(menu_Select)
  195. {
  196. case 0:
  197. std::cout << "\nKtory wpis wyswietlic? ";
  198. std::cin >> ktoryWpis;
  199. show::Wpis(get::zPliku, ktoryWpis);
  200. std::cout << "\n\nNacisnij dowolny klawisz aby kontynuowac...";
  201. _getch();
  202. menu_Semafor=0;
  203. MenuShow(menu, menu_Select, hOut);
  204. break;
  205. case 1:
  206. int zakresOd, zakresDo;
  207. std::cout << "Podaj zakres wpisow: [od do]: ";
  208. scanf("%d %d", &zakresOd, &zakresDo);
  209. show::Wpis(get::zPliku, zakresOd, zakresDo);
  210. _getch();
  211. menu_Semafor=0;
  212. MenuShow(menu, menu_Select, hOut);
  213. break;
  214. case 2:
  215. show::Wpis(get::zPliku);
  216. std::cout << "\n\nNacisnij dowolny klawisz aby kontynuowac...";
  217. _getch();
  218. menu_Semafor=0;
  219. MenuShow(menu, menu_Select, hOut);
  220. break;
  221. case 3:
  222. int zakresOd2, zakresDo2;
  223. zakresOd2 = get::zPliku.size()-10;
  224. zakresDo2 = get::zPliku.size();
  225. show::Wpis(get::zPliku, zakresOd2, zakresDo2);
  226. _getch();
  227. menu_Semafor=0;
  228. MenuShow(menu, menu_Select, hOut);
  229. break;
  230. case 4:
  231. return 0;
  232. }
  233. }
  234. }
  235. }
  236.  
  237. void MenuShow (std::vector<std::string> menu, int menu_Select, HANDLE hOut)
  238. {
  239. SetConsoleTextAttribute(hOut, 0);
  240. system("CLS");
  241. for(unsigned int i = 0; i < menu.size(); i++)
  242. {
  243. SetConsoleTextAttribute(hOut, 10);
  244. std::cout << i+1 << " ";
  245. if(menu_Select == i) SetConsoleTextAttribute(hOut, FR | BW);
  246. else SetConsoleTextAttribute(hOut, FW | B0);
  247. std::cout << menu[i] << std::flush << std::endl;
  248. }
  249. SetConsoleTextAttribute(hOut, FW | B0);
  250.  
  251. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement