BG Development


  Reply to this topicStart new topicStart Poll

> C++, Не знам как да оправя грешката, не файл
Dbs23272
Публикувано на: 13-01-2022, 10:15
Quote Post



Име:
Група: Потребител
Ранг: Новопостъпил

Мнения: 3
Регистриран на: 13.01.22



CODE
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#define N 30
using namespace std;
struct abonati
{
      char name[30];
      char adres[30];
      int number;
      int suma;
}p;
vector<abonati> v;
fstream out("Data.txt", ios::out);
int read_phone()
{
      int n;
      cout << "Broj abonati: ";
      cin>>n;
 
      for(int i=0; i<n; ++i)
      {
            cout<<"Vyvedete ime: "; cin>>p.name;
            cout<<"Vyvedete adres: "; cin>>p.adres;
            cout<<"Vyvedete nomer: "; cin>>p.number;
            cout<<"Vyvedete suma: "; cin>>p.suma;
        
            out.write((char*)&p, sizeof(struct abonati));
            v.push_back(p);
      }

}
void Sort()
{
      int n = v.size();
      abonati temp;
 
 
      for(int i=0; i<n; ++i)
      {
            temp.suma = v[i].suma;
        
            for(int j=i; j<n; ++j)
            {
                  if(temp.suma > v[j].suma) temp=v[j];
      
            }
                         cout << "Ime:  " << temp.name << endl;
                         cout << "Adres:  " << temp.adres << endl;
                         cout << "Nomer:  " << temp.number << endl;
                         cout << "Suma:  " << temp.suma << endl;
                         cout << "======================\n";
            
      }
}
void spravka()
{
      int len = v.size();
 
      cout << "Spravka:\n";
      for(int i=0; i<len; i++)
      {
            if(v[i].suma > 100)
            {
                  cout << "Ime:  " << v[i].name << endl;
                  cout << "Adres:  " << v[i].adres << endl;
                  cout << "Nomer:  " << v[i].number << endl;
                  cout << "Suma:  " << v[i].suma << endl;
              
                  cout << "======================\n";
            }
      }
}

int main()
{ int key=0;
do{
cout<<"=====================================\n";
cout<<" 1.Vyvejdane na abonat\n";
cout<<" 2.Izvejdane na spravka za abonati\n";
cout<<" 3.Sortirane na abonati \n";
cout<<" 4.Izhod\n";
cout<<"\nMolq izberete obciq: ";
cin >> key;
}while(key>4 || key<1);
switch(key)
{ case 1: read_phone(); main();
            break;
 case 2: spravka(); main();
            break;
 case 3: Sort(); main();
            break;
}
system("PAUSE");
return EXIT_SUCCESS;
}


Това мнение е било редактирано от DarkOne на 13-01-2022, 11:01
PMEmail Poster
Top
1 потребители преглеждат тази тема в момента (1 гости, 0 анонимни потребители)
Потребители, преглеждащи темата в момента:

Topic Options Reply to this topicStart new topicStart Poll

 


Copyright © 2003-2019 | BG Development | All Rights Reserved
RSS 2.0