Aleksandr_Grigoryev

Форматированный ввод

Mar 12th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <iomanip>
  4. #include <string>
  5. #include <windows.h>
  6. using namespace std;
  7. const int t = 5;
  8. const int lengthColumn = 20;
  9. const int Indent = 7;
  10. const int lengthTable = 106;
  11.  
  12. void star1(ofstream &f, int n, int m)
  13. {
  14.     f.width(n);
  15.     int i;
  16.     for (i = 0; i<m; i++)
  17.         f << '*';
  18.     f << endl;
  19. }
  20. void star2(ofstream &f, int n, int m)
  21. {
  22.     f.width(n);
  23.     int i;
  24.     for (i = 0; i<m; i++)
  25.         f << '*';
  26. }
  27.  
  28. void table(ifstream &fin1, ifstream &fin2, ofstream &f, int m, int a[4][5], char s1[16])
  29. {
  30.     int i;
  31.     for (i = 0; i<m; i++)
  32.     {
  33.         if (i == 0)
  34.         {
  35.             star1(f,Indent + 1, lengthTable);
  36.             f.width(Indent + 1); f << '*';
  37.             f.width(lengthColumn + 1); f << '*';
  38.             for (int j = 0; j<t - 1; j++)
  39.             {
  40.                 f.width(15);
  41.                 fin2 >> s1; f << s1;
  42.                 memset(s1, ' ', 16);
  43.                 star2(f,t + 1, 1);
  44.             }
  45.             f << endl;
  46.         }
  47.         else
  48.         {
  49.             star1(f,Indent + 1, lengthTable);
  50.             star2(f,Indent + 1, 1);
  51.             f.width(15);
  52.             fin2 >> s1; f << s1;
  53.             memset(s1, ' ', 16);
  54.             star2(f,t + 1, 1);
  55.             for (int j = 0; j<t - 1; j++)
  56.             {
  57.                 f.width(11); fin1 >> a[j][i - 1];
  58.                 f << a[j][i - 1]; star2(f,10, 1);
  59.             }
  60.             f << endl;
  61.         }
  62.     }
  63.     star1(f,Indent + 1, lengthTable);
  64. }
  65.  
  66. int main()
  67. {
  68.     setlocale(LC_ALL, "Russian");
  69.     int matrix[t - 1][t] = { 0 };
  70.     int sr;
  71.     char s[16];
  72.     int sum = 0;
  73.     ifstream fin1("Text.txt");
  74.     string str;
  75.     cout << "Введите название";
  76.     getline(cin, str);
  77.     ifstream fin2("input1.txt");
  78.     ofstream out("Text1.txt");
  79.     out << endl;
  80.     out.width(Indent + 57);
  81.     out << str;
  82.     out.width(lengthTable - 57);
  83.     out << endl;
  84.     table(fin1, fin2,out, t + 1, matrix, s);
  85.     out.width(Indent + 1);
  86.     out << '*';
  87.     out.width(18); out << "СРЕДНЕЕ ЗНАЧЕНИЕ";
  88.     star2(out,Indent -4, 1);
  89.     fin1.close();
  90.     fin2.close();
  91.  
  92.     for (int i = 0; i<t - 1; i++)
  93.     {
  94.         out.width(11);
  95.         for (int j = 0; j < t; j++)
  96.         sum += matrix[i][j];
  97.         sr = sum / 5;
  98.         out << sr; star2(out,10, 1);
  99.         sr = 0;
  100.     }
  101.     out << endl;
  102.     star1(out,Indent + 1, lengthTable);
  103.     system("pause");
  104.     return 0;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment