pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

C++ pastebin - collaborative debugging tool View Help


Posted by Profas on Tue 16 Dec 02:52 (modification of post by Profas view diff)
report abuse | View followups from Profas | download | new post

  1. //----------------------------------------------------------------------------------------------------
  2. /*
  3. Programa: Studentu saraso apdorojimas is failo pagal pavarde, varda, grupes sifra,
  4.           pazymius, isvedimas i ekrana ivairiais budais, bei studentu trinimas
  5.           is saraso. Programa su komandiniu interfeisu.        
  6. Grupe: PKV07.  
  7. Dalykas: Strukturinis programavimas ir algoritmai.
  8. Destytojas: Lekt. R.Gaivenis.
  9. Atliko: Andrius Kuznecovas.
  10. */
  11. //----------------------------------------------------------------------------------------------------
  12.  
  13. #include <iostream>
  14. #include <fstream>
  15. #include <string.h>
  16. #include <stdio.h>
  17.  
  18. using namespace std;
  19.  
  20. //----------------------------------------------------------------------------------------------------
  21.  
  22. string ReadWord(int line, int word, string text, string sign, bool only_line);
  23. string ReadFile();
  24. string LineDelete(int nr, string info);
  25. void Menu(string info);
  26. void Line(int nr);
  27. void Write(string info);
  28. void Intro();
  29. void View();
  30. void Delete(string info);
  31. int LineCount(string info);
  32. int Count(int student, int mark, string info);
  33.  
  34. //----------------------------------------------------------------------------------------------------
  35.  
  36. int main()
  37. {
  38.     Intro();
  39.    
  40.     string info = ReadFile();
  41.    
  42.     Menu(info);
  43.    
  44.     system("pause>nul");
  45.     return 0;
  46. }
  47.  
  48. //----------------------------------------------------------------------------------------------------
  49.  
  50. int Count(int student, int mark, string info)
  51. {
  52.     int howmany=0;
  53.    
  54.     for(int i=4;i<10;i++)
  55.         if(atoi((ReadWord(student,i,info,":",false)).c_str()) == mark)
  56.             howmany++;
  57.            
  58.     return howmany;
  59. }
  60.  
  61. //----------------------------------------------------------------------------------------------------
  62.  
  63. int LineCount(string info)
  64. {
  65.     int line = 0;
  66.  
  67.     for (int i = 0; i < info.length(); i++)
  68.         if (info[i] == '$')
  69.             ++line;
  70.  
  71.     return line;
  72. }
  73.  
  74. //----------------------------------------------------------------------------------------------------
  75.  
  76. void View()
  77. {
  78.      system("CLS");
  79.          
  80.      int type;
  81.      string info = ReadFile();
  82.          
  83.      Line(2);
  84.      cout << "# STUDENTU SARASAI.\n";
  85.      Line(2);
  86.      cout << "# Iveskite saraso tipo numeri:\n";
  87.      cout << "# 1. Nuoseklus sarasas.\n";
  88.      cout << "# 2. Sarasas korteles forma.\n";
  89.      Line(2);
  90.      cout << "# ";
  91.      
  92.      cin >> type;
  93.      
  94.      system("CLS");
  95.      
  96.      if(type == 1)
  97.      {
  98.          Line(2);
  99.          cout << "---------------- STUDENTU SARASAS -----------------\n";
  100.          
  101.          if(info!="")
  102.          {
  103.              int lines = LineCount(info)+1;
  104.              
  105.              if(lines!=1)
  106.              {
  107.                  Line(2);
  108.                  cout << "# NR : PAVARDE : VARDAS : GRUPE : 10 : 9 : 8\n";
  109.                  Line(2);
  110.                  
  111.                  for(int i=1;i<lines;i++)
  112.                  {
  113.                      cout << "# " << i <<" : ";
  114.                      cout << ReadWord(i,1,info,":",false) << " : ";
  115.                      cout << ReadWord(i,2,info,":",false) << " : ";
  116.                      cout << ReadWord(i,3,info,":",false) << " : ";
  117.                      cout << Count(i,10,info) << " : ";
  118.                      cout << Count(i,9,info) << " : ";
  119.                      cout << Count(i,8,info) << "\n";    
  120.                  }          
  121.                  
  122.                  Line(2);
  123.              }      
  124.              else
  125.                  cout << "! STUDENTU SARASE NERA.\n";        
  126.          }
  127.          else
  128.          {
  129.              Line(2);
  130.              cout << "! FAILAS TUSCIAS ARBA FAILO NERA.\n";
  131.          }      
  132.      }
  133.      
  134.      if(type == 2)
  135.      {  
  136.          Line(2);
  137.          cout << "---------------- STUDENTU SARASAS -----------------\n";
  138.      
  139.          if(info!="")
  140.          {
  141.              int lines = LineCount(info)+1;
  142.  
  143.              if(lines!=1)
  144.              {
  145.                  for(int i=1;i<lines;i++)
  146.                  {
  147.                      Line(2);
  148.                      cout << "! STUDENTAS NR: " << i << ".\n";
  149.                      cout << "# PAVARDE: " << ReadWord(i,1,info,":",false) << ".\n";
  150.                      cout << "# VARDAS: " << ReadWord(i,2,info,":",false) << ".\n";
  151.                      cout << "# GRUPE: " << ReadWord(i,3,info,":",false) << ".\n";
  152.                      cout << "# PAZYMIAI: \n";
  153.                      cout << "# - Desimtuku: " << Count(i,10,info) << ".\n";
  154.                      cout << "# - Devintuku: " << Count(i,9,info) << ".\n";
  155.                      cout << "# - Astuntuku: " << Count(i,8,info) << ".\n";                                  
  156.                  }
  157.              
  158.                  Line(2);
  159.              }
  160.              else
  161.                  cout << "! STUDENTU SARASE NERA.\n";
  162.              
  163.          }
  164.          else
  165.          {
  166.              Line(2);
  167.              cout << "! FAILAS TUSCIAS ARBA FAILO NERA.\n";
  168.          }
  169.      }
  170.      
  171.      cin.get();
  172. }
  173.  
  174. //----------------------------------------------------------------------------------------------------
  175.  
  176. void Delete(string info)
  177. {
  178.      system("CLS");
  179.      
  180.      int nr;
  181.      
  182.      Line(2);
  183.      cout << "# TRINAMAS STUDENTAS.\n";
  184.      Line(2);
  185.      
  186.      cout<< "# Iveskite studento nr:\n# ";
  187.      cin >> nr;
  188.      
  189.      if((nr>0) && (nr<LineCount(info)+1))
  190.      {
  191.          info = LineDelete(nr-1,info);
  192.          Write(info);
  193.          system("CLS");
  194.          Line(2);
  195.          cout << "! STUDENTAS NR: " << nr << " PASALINTAS\n";
  196.      }
  197.      else
  198.      {
  199.          Line(2);
  200.          cout << "! TOKIOS STUDENTO SARASE NERA.\n";
  201.      }
  202.      
  203.      cin.get();
  204. }
  205.  
  206. //----------------------------------------------------------------------------------------------------
  207.  
  208. string LineDelete(int nr, string info)
  209. {
  210.     int current = 0;
  211.     string buf = "";
  212.  
  213.     if (nr != 0)
  214.     {
  215.         for (int i = 0; i < info.length(); i++)
  216.         {
  217.             if (info[i] == '$')
  218.                 current++;
  219.  
  220.             if (current == nr)
  221.             {
  222.                 while (info[++i] != '$')
  223.                     current++;
  224.             }
  225.  
  226.             if (i <= info.length())
  227.                 buf += info[i];
  228.         }
  229.     }
  230.     else
  231.     {
  232.         int line = 0;
  233.  
  234.         while (info[line++] != '$')
  235.             continue;
  236.  
  237.         for (int i = line; i < info.length(); i++)
  238.             buf += info[i];
  239.      }
  240.  
  241.      return buf;
  242. }
  243.  
  244. //----------------------------------------------------------------------------------------------------
  245.  
  246. void Write(string info)
  247. {
  248.      ofstream file ("duomenys.txt");
  249.      
  250.      file << "";
  251.      
  252.      file << info;
  253.      
  254.      file.close();
  255. }
  256.  
  257. //----------------------------------------------------------------------------------------------------
  258.  
  259. void Intro()
  260. {
  261.      Line(1);
  262.      cout << "############## STUDENTU DUOMENU BAZE ##############\n";
  263.      Line(1);
  264.      cout << "############## SUKURE: Andrius Kuznecovas #########\n";
  265.      cout << "############## GRUPE : PKV07 ######################\n";
  266.      Line(1);
  267. }
  268.  
  269. //----------------------------------------------------------------------------------------------------
  270.  
  271. void Line(int nr)
  272. {
  273.      if(nr==1)
  274.          cout << "###################################################\n";
  275.      if(nr==2)
  276.          cout << "---------------------------------------------------\n";
  277. }
  278.  
  279. //----------------------------------------------------------------------------------------------------
  280.  
  281. void Menu(string info)
  282. {
  283.      string command;
  284.      
  285.      while(command != "iseiti")
  286.      {
  287.           command = "";
  288.          
  289.           Line(2);
  290.           cout << "# KOMANDOS: ziureti, istrinti, iseiti. #\n";
  291.           Line(2);
  292.           cout << "# ";
  293.          
  294.           getline(cin,command);
  295.  
  296.           if(command == "istrinti")
  297.               Delete(info);
  298.              
  299.           if(command == "ziureti")
  300.               View();
  301.      }
  302.      
  303.      system("CLS");
  304.      Line(2);
  305.      cout << "# PROGRAMOS DARBO PABAIGA. VISO GERO.\n";
  306.      Line(2);
  307. }
  308.  
  309. //----------------------------------------------------------------------------------------------------
  310.  
  311. string ReadFile()
  312. {
  313.     string info;
  314.     ifstream file ("duomenys.txt");
  315.    
  316.     if(file.is_open())
  317.         while (! file.eof() )
  318.         {
  319.              string buf;
  320.              getline(file,buf);
  321.              info+=buf;
  322.         }
  323.     else
  324.         return "";
  325.    
  326.     file.close();
  327.    
  328.     return info;
  329. }
  330.  
  331. //----------------------------------------------------------------------------------------------------
  332.  
  333. string ReadWord(int line, int word, string text, string sign, bool only_line)
  334. {
  335.     string buf = "";
  336.     string text_line = "";
  337.     int line_nr = 0;
  338.     int sign_nr = 1;
  339.     bool end = false;
  340.  
  341.     --line;
  342.     if (word > 0)
  343.     {
  344.         for (int i = 0; i < text.length(); i++)
  345.         {
  346.             if (line != 0)
  347.             {
  348.                 if (text[i] == '$')
  349.                     line_nr++;
  350.                 else
  351.                     continue;
  352.  
  353.                 if (line_nr == line)
  354.                 {
  355.                     ++i;
  356.                     while ((i != text.length()) && (text[i] != '$'))
  357.                          text_line += text[i++];
  358.  
  359.                     if (only_line != false)
  360.                         return text_line;
  361.  
  362.                         break;
  363.                 }
  364.             }    
  365.             else
  366.             {
  367.                 while ((i != text.length()) && (text[i] != '$'))
  368.                     text_line += text[i++];
  369.  
  370.                     if (only_line != false)
  371.                         return text_line;
  372.  
  373.                     break;
  374.             }
  375.         }
  376.  
  377.         for (int i = 0; i < text_line.length(); i++)
  378.         {
  379.             if (word == 1)
  380.             {
  381.                 while ((i != text_line.length()) && (text_line[i] != sign[0]) && (text[i] != '$'))
  382.                     buf += text_line[i++];
  383.  
  384.                     return buf;
  385.             }
  386.             else
  387.             {
  388.                 for (int j = 0; j < text_line.length(); j++)
  389.                 {
  390.                     while (sign_nr != word)
  391.                         if (text_line[j++] == sign[0])
  392.                             sign_nr++;
  393.  
  394.                     while ((j != text_line.length()) && (text_line[j] != '$') && (text_line[j] != sign[0]))
  395.                         buf += text_line[j++];
  396.  
  397.                     end = true;
  398.  
  399.                     if (end == true)
  400.                         break;
  401.                 }
  402.             }
  403.             if (end == true)
  404.                 break;
  405.        }
  406.     }
  407.     else
  408.         return NULL;
  409.  
  410.     if (buf != "")
  411.         return buf;
  412.     else
  413.         return NULL;
  414. }
  415.  
  416. //----------------------------------------------------------------------------------------------------

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post