Advertisement
SUni2020

1 semester c++

Jul 18th, 2020
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.09 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. #include<string>
  4. int const num = 2;
  5. const string character = ".";
  6. struct Streets {
  7.  
  8.     string name;
  9.     double lenght;
  10.     int numofsvetofari;
  11. };
  12. void readStreets (Streets & s) {
  13.     cout << "  danni za ulica:\n";
  14.     do {
  15.         cout << "      ime na ulica: ";
  16.         cin >> s.name;
  17.     } while (s.name.find != string::npos)
  18.     do {
  19.         cout << "      dyljina na ulica: ";
  20.         cin >> s.lenght;
  21.     } while (s.lenght < 0);
  22.     do {
  23.         cout << "      broi na svetofari na ulica: ";
  24.         cin >> s.numofsvetofari;
  25.     } while (s.numofsvetofari < 0);
  26. }
  27. void writeStreets(Streets s) {
  28.     cout << "    Ime na ulica: " << s.name << "\n"
  29.         << "Dyljina na ulica " << s.lenght << "\n"
  30.         <<"Broi na svetofari: " << s.numofsvetofari << endl;
  31. }
  32. void readMas(Streets c[], int M) {
  33.     cout << "Vyvedete danni za ulicata: "<< M << " :\n";
  34.     for (int i = 0; i < M; ++i) {
  35.         cout << i + 1 <<"\n";
  36.         readStreets(c[i]);
  37.     }
  38. }
  39. int main() {
  40.     system("chcp 1251");
  41.     Streets ar[num];
  42.     readMas(ar, num);
  43.     for (Streets s : ar) {
  44.  
  45.         if (s.numofsvetofari == 0) {
  46.             cout << "Ulici bez svetofari: << \n ";
  47.             writeStreets(s);
  48.         }
  49.     }
  50.     string podniz;
  51.     cout << "Въведете търсен подниз: ";
  52.     getline(cin, podniz);
  53.     cout << "Ulici название, съдържащо uj \"" << podniz << "\":\n";
  54.     for (Streets s : ar)
  55.         if (s.name.find(podniz) == "uj")
  56.             writeStreets(s);
  57.     cout << "  (край)\n\n";
  58.     system("pause");
  59.     string podniz;
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.     cout << "Wywedi podniz: ";
  67.     getline(cin, podniz);
  68.     for (Goods g : ar)
  69.         if (s.name.find(podniz) == "uj")
  70.             writeGoods(g);
  71.     if (s.name == "юж") {
  72.         cout << "Ulici s nazwanie,sydyrjashto uj \"" << podniz << "\":\n";
  73.         for (Streets s : ar)
  74.             writeStreets(s);
  75.     }
  76.     system("pause");
  77. }
  78.        
  79.  
  80.  
  81.  
  82.  
  83. // Файл progr19_09_04.cpp към Задача 9.04
  84. #include <iostream>
  85. using namespace std;
  86. #include <string>
  87. int const number = 3; // брой на стоките
  88. const string chAll = "0123456789 ,.-"
  89. "абвгдежзийклмнопрстуфхцчшщъьюя"
  90. "abcdefghijklmnopqrstuvwxyz"
  91. "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  92. //допустими знакове в названието на стока
  93. struct Goods {
  94.     string kind;
  95.     double price;
  96. };
  97. void readGoods(Goods & g) { // задължително със знак &
  98.     cout << "  данни за стока:\n";
  99.     do {
  100.         cout << "      цена: ";
  101.         cin >> g.price;
  102.     } while (g.price <= 0.0);
  103.     getline(cin, g.kind); // изчиства буфера на клавиатурата
  104.     do {
  105.         cout << "      название: ";
  106.         getline(cin, g.kind);
  107.     } while (g.kind == "" ||
  108.         string::npos != g.kind.find_first_not_of(chAll));
  109. }
  110. void writeGoods(Goods g) {
  111.     cout << "    Стока: " << g.kind
  112.         << "; цена: " << g.price << endl;
  113. }
  114. void readAarray(Goods a[], int L) {
  115.     cout << "Въвеждайте данни за " << L << " стоки:\n";
  116.     for (int i = 0; i < L; ++i) {
  117.         cout << "  " << i + 1 << ".";
  118.         readGoods(a[i]);
  119.     }
  120. }
  121. int main() {
  122.     system("chcp 1251");
  123.     Goods ar[number];
  124.     readAarray(ar, number);
  125.     double max = 0.0;
  126.     for (Goods g : ar)
  127.         if (g.price > max)
  128.             max = g.price;
  129.     cout << "Максимална цена: " << max
  130.         << "\nСтоки с тасзи цена:\n";
  131.     for (Goods g : ar)
  132.         if (g.price == max)
  133.             cout << "  " << g.kind << endl;
  134.     string podniz;
  135.     cout << "Въведете търсен подниз: ";
  136.     getline(cin, podniz);
  137.     cout << "Ulici название, съдържащо uj \"" << podniz << "\":\n";
  138.     for (Streets s : ar)
  139.         if (s.name.find(podniz) == "uj")
  140.             writeStreets(s);
  141.     cout << "  (край)\n\n";
  142.     system("pause");
  143. }
  144.  
  145. // Файл progr19_09_04.cpp към Задача 9.04
  146. #include <iostream>
  147. using namespace std;
  148. #include <string>
  149. int const number = 3; // брой на стоките
  150. const string chAll = "0123456789 ,.-"
  151. "абвгдежзийклмнопрстуфхцчшщъьюя"
  152. "abcdefghijklmnopqrstuvwxyz"
  153. "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  154. //допустими знакове в названието на стока
  155. struct Goods {
  156.     string kind;
  157.     double price;
  158. };
  159. void readGoods(Goods & g) { // задължително със знак &
  160.     cout << "  данни за стока:\n";
  161.     do {
  162.         cout << "      цена: ";
  163.         cin >> g.price;
  164.     } while (g.price <= 0.0);
  165.     getline(cin, g.kind); // изчиства буфера на клавиатурата
  166.     do {
  167.         cout << "      название: ";
  168.         getline(cin, g.kind);
  169.     } while (g.kind == "" ||
  170.         string::npos != g.kind.find_first_not_of(chAll));
  171. }
  172. void writeGoods(Goods g) {
  173.     cout << "    Стока: " << g.kind
  174.         << "; цена: " << g.price << endl;
  175. }
  176. void readAarray(Goods a[], int L) {
  177.     cout << "Въвеждайте данни за " << L << " стоки:\n";
  178.     for (int i = 0; i < L; ++i) {
  179.         cout << "  " << i + 1 << ".";
  180.         readGoods(a[i]);
  181.     }
  182. }
  183. int main() {
  184.     system("chcp 1251");
  185.     Goods ar[number];
  186.     readAarray(ar, number);
  187.     double max = 0.0;
  188.     for (Goods g : ar)
  189.         if (g.price > max)
  190.             max = g.price;
  191.     cout << "Максимална цена: " << max
  192.         << "\nСтоки с тасзи цена:\n";
  193.     for (Goods g : ar)
  194.         if (g.price == max)
  195.             cout << "  " << g.kind << endl;
  196.     string sub;
  197.     cout << "Въведете търсен подниз: ";
  198.     getline(cin, sub);
  199.     cout << "Стоки с название, съдържащо \"" << sub << "\":\n";
  200.     for (Goods g : ar)
  201.         if (g.kind.find(sub) != string::npos)
  202.             writeGoods(g);
  203.     cout << "  (край)\n\n";
  204.     system("pause");
  205. }
  206.  
  207.  
  208. #include<iostream>
  209. #include<string>
  210. using namespace std;
  211. int main()
  212. {  
  213.     system("chcp 1251");
  214.     string str, sub;
  215.     cout << "Wywedete 1-niz: ";
  216.     getline(cin, str);
  217.     cout << "Wywedete 2-niz: ";
  218.     getline(cin, sub);
  219.     int inumber = 0;
  220.     if(str.substr(begin,len))
  221.        
  222.     system("pause");
  223.    
  224. }
  225.  
  226. #include <iostream>
  227. using namespace std;
  228. int main() {
  229.     system("chcp1251");
  230.     double a, b, c, s, p;
  231.     cout << "Wywedete 3 cisla:";
  232.  
  233.  
  234.     system("pause");
  235. }
  236.  
  237. #include <iostream>
  238. using namespace std;
  239.  
  240. /*Да се напишат дефинициите на следните функции:
  241. а) за намиране на средното аритметично на елементите на масив от цели числа;
  242. б) за намиране на броя на двойките равни съседни елементи в масив от цели числа;
  243. в) за увеличаване с 12 на всички минимални елементи на масив от цели числа;
  244. Функциите трябва да могат да работят с масиви с различни дължини */
  245.  
  246. // а) за намиране на средното аритметично на елементите на масив от цели числа;
  247. int CountofMaxRealArray(double anArray[], const int size)
  248. {
  249.     int count = 0;
  250.     double max = anArray[0];
  251.     for (int i = 1; i < size; i++)
  252.         if (anArray[i] < max)
  253.             max = anArray[i];
  254.     return count;
  255. }
  256.  
  257. // б) за намиране на броя на двойките равни съседни елементи в масив от цели числа;
  258. int  CountOfAdjacentEqual(int anArray[], const int size)
  259. {
  260.     int count = 0;
  261.     for (int i = 0; i < size - 1; i++) // от първия (0) до предпоследния (size-2)
  262.         if (anArray[i] == anArray[i + 1])
  263.             count++;
  264.     return count;
  265. }
  266.  
  267. // в) за увеличаване с x на всички минимални елементи на масив от цели числа;
  268. int  IncrementMinimalElements(int anArray[], const int size, int x)
  269. {
  270.     int min = anArray[0];
  271.     for (int i = 1; i < size; i++)
  272.         if (anArray[i] < min)
  273.             min = anArray[i];
  274.     int count = 0;
  275.     for (int i = 0; i < size; i++)
  276.         if (anArray[i] == min)
  277.         {
  278.             anArray[i] = anArray[i] + x;
  279.             count++;
  280.         }
  281.     return count;
  282. }
  283.  
  284. int main()
  285. {
  286.     int Array[10] = { 1,2,3,4,5,6,7,8,9,10 };
  287.     cout << "a) Average of the array is " << AverageIntArray(Array, 10) << endl;
  288.  
  289.     int Array2[11] = { 1, 2, 2, 3, 4, 4, 5, 6, 7, 7, 8 };
  290.     cout << "b) Count of the adjacent equal elements of the array2 is "
  291.         << CountOfAdjacentEqual(Array2, 11) << endl;
  292.  
  293.     int Array3[11] = { 3, 2, 4, 3, 2, 4, 2, 6, 7, 2, 8 };
  294.     cout << "c) Count of the minimal elements of the array3 is "
  295.         << IncrementMinimalElements(Array3, 11, 12) << endl;
  296.     for (int i = 0; i < 11; i++) cout << Array3[i] << " ";
  297.     return 0;
  298. }
  299.  
  300.  
  301.  
  302. #include<iostream>  
  303. #include <iomanip>
  304. #include<bitset>
  305. #include<string>
  306. using namespace std;
  307.  
  308. int main()
  309. {
  310.     system("chcp 1251");
  311.     int num;
  312.     do {
  313.         cout << "Wywedete cqlo cislo ot 1 do 1000:";
  314.             cin >> num;
  315.     } while (num < 1 || 1000 < num);
  316.     cout << "16-cen zapis:" << hex << num << endl;
  317.     cout << "8-cen zapis:" << oct << num << dec<<endl;
  318.    
  319.     for (int base = 7; 3 <= base; --base) {
  320.         string str = "";
  321.         int n = num;
  322.         do {
  323.             str = (char)('0' + n % base) + str;
  324.             n /= base;
  325.         } while(n);
  326.         cout <<base<< "-icen zapis:" << bitset<11>(num) << endl;
  327.     }cout << "2-cen zapis:" << bitset<11>(num) << endl;
  328.  
  329.  
  330.     system("pause");
  331.     return 0;
  332. }
  333.  
  334.  
  335. #include<iostream>  
  336. using namespace std;
  337. #include <string>
  338. int main()
  339. {  
  340.     system("chcp 1251");
  341.     int s;
  342.     cout << "Enter a whole number bigger than 1:";
  343.     cin >> s;
  344.     string valStr;
  345.     cout << "Enter" << s << "-icen zapis na cqlo cislo:";
  346.     cin >> valStr;
  347.     cout << "10-icna stoinost :" << stoi(valStr, NULL, s) << endl;
  348.     system("pause");
  349.  
  350.     return 0;
  351. }
  352.  
  353. using System;
  354.  
  355. namespace IntroToCSharp
  356. {
  357.     class HelloCSharp
  358.     {
  359.         static void Main()
  360.         {
  361.             int numberInHex; //declare
  362.             numberInHex = 0x100; // initiliaze
  363.             Console.WriteLine(numberInHex);
  364.  
  365.  
  366.             int intValue2 = 0x100;
  367.             Console.WriteLine(intValue2);
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375.         }  
  376.     }
  377. }
  378.  
  379.  
  380.  
  381. int main() {
  382.     const int n = 20; // брой на оценките  double list[n]; // масив с оценки
  383.                       // въвеждане на оценките от клавиатурата  for(int i=0; i<n; ++i)  
  384.     {    do{  // въвеждането е с проверка за коректност      
  385.         cout << "Evaluation for student No " << i+1 << ": ";      cin >> list[i];    
  386.     }while(list[i]<2.0 || list[i]>6.0); // само от 2 до 6  }
  387.                                         // извеждане на списъка с оценки на екрана  
  388.     cout << endl << "----- Results -----\n";  c
  389.         out.setf(ios::fixed|ios::showpoint);
  390.     cout.precision(2);  for(int i=0; i<n; ++i)   cout << "Student No " << i+1 << " - \t"    << "evaluation: " << list[i] << endl;  cout << endl;  return 0; }
  391.  
  392. # include <iostream>
  393. using namespace std;
  394. int main() {
  395.     system("chcp 1251");
  396.     char ch;
  397.     cout << "Enter znak:";
  398.         cin >> ch;
  399.         if ('a' <= ch && ch <= 'z')
  400.             cout << "Towa e " << ch - 'a' + 1
  401.             << "-a malka latinska bukwa .\n",
  402.         else cout << "Towa ne malka latinska bukwa.\n",
  403.             double x y;
  404.             cout << "Wywedete dwe cisla:";
  405.             cin >> x >> y;
  406.             char rel = x < y ? '<' : x == y
  407.                 ? '=' : '>';
  408.  
  409.             int odd, even;
  410.             do
  411.             cout << "Enter znak:";
  412.             cin >> ch;
  413.  
  414.  
  415.  
  416.     system("pause");
  417. }
  418.  
  419.  
  420. #include <iostream>  
  421.  
  422. using namespace std;
  423.  
  424. int main()
  425. {
  426.  
  427.     cout<<"Hello World";
  428.      
  429.     return 0;
  430. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement