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