Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Zadanie 1.
- #include <iostream>
- #include <fstream>
- using namespace std;
- int main()
- {
- fstream plik;
- string lancuch;
- plik.open("D:\\nazwa.txt", ios::out); // otwarcie pliku do zapisu
- do{
- cin >> lancuch; //odczyt znakow z klawiatury
- if(lancuch=="0") break;
- plik << lancuch <<" ";
- }while(lancuch!="0");
- plik.close();
- return 0;
- }
- /------------------------------------------------------------
- Zadanie 2.
- #include <iostream>
- #include <fstream>
- using namespace std;
- struct TData{
- int a;
- };
- int main()
- {
- TData a;
- TData *b = &a;
- cin>>(*b).a;
- cout<<a.a;
- return 0;
- }
- /------------------------------------------------------------
- Zadanie 3.
- #include <iostream>
- using namespace std;
- bool palindrom(string text)
- {
- for(int i=0;i<text.length();i++)
- {
- text[i]=tolower(text[i]);
- }
- for(int i=0;i<text.length();i++)
- {
- if(text[i]!=text[text.length()-(i+1)])
- {
- return false;
- }
- }
- return true;
- }
- int main()
- {
- string lancuch;
- cin>>lancuch;
- if(palindrom(lancuch)) cout<<"Jest palindromem";
- else cout<<"Nie jest palindromem";
- return 0;
- }
- /------------------------------------------------------------
- Zadanie 4.
- #include <iostream>
- #include <fstream>
- #include <cstdlib>
- using namespace std;
- int main()
- {
- fstream plik;
- string lancuch, tmp="", multi="";
- plik.open("D:\\nazwa.txt", ios::in);
- double suma=0, liczba=0;
- int z=0;
- while (!plik.eof())
- {
- liczba=0;
- tmp="";
- getline(plik, lancuch);
- if((int)lancuch[0]>47 && (int)lancuch[0]<58)
- {
- multi="";
- cout<<endl<<lancuch[0]<<" x ";
- multi=lancuch[0];
- liczba=atof(multi.c_str());
- }
- for(int i=lancuch.length();i>0;i--)
- {
- if(lancuch[i]==' ')
- {
- z=i;
- break;
- }
- }
- for(int i=z+1;i<lancuch.length();i++)
- {
- tmp+=lancuch[i];
- }
- if(liczba==0) suma+=atof(tmp.c_str());
- else suma+=(atof(tmp.c_str())*liczba);
- cout<<tmp<<endl;
- }
- cout<<"Rachunek: "<< suma;
- plik.close();
- return 0;
- }
- /------------------------------------------------------------
- Zadanie 5.
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <cstdio>
- using namespace std;
- int main()
- {
- string linia;
- fstream plik;
- fstream plik2;
- plik.open( "D:\\nazwa.txt", ios::in );
- plik2.open( "D:\\nazwa1.txt", ios::out | std::ios::out | ios::trunc );
- string a;
- string b;
- cout << "Podaj szukany tekst: ";
- cin >> a;
- cout << "Zamien na: ";
- cin >> b;
- int n;
- if( plik.good() == true and plik2.good() == true )
- {
- while( !plik.eof() )
- {
- getline( plik, linia );
- do{
- n = linia.find( a, 0 );
- if( n != - 1 )
- {
- linia.replace( n, a.size(), b );
- }
- }while (n!=-1);
- plik2 << linia << endl;
- cout << linia << endl;
- }
- }
- plik.open( "D:\\nazwa.txt", ios::out );
- while( !plik2.eof() )
- {
- getline( plik2, linia );
- plik << linia << endl;
- cout << linia << endl;
- }
- plik.close();
- plik2.close();
- system("del D:\\nazwa.txt");
- rename ("D:\\nazwa1.txt", "D:\\nazwa.txt");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement