Results 1 to 3 of 3
Thread: c++
Hybrid View
-
25th September 2016 16:38 #1Registered User
Join Date: Sep:2016
Location: Bulgaria
Posts: 2
c++
.
, . . . , n , x- (Bubblesort). . .
.
Code:#include <iostream.h> #include <stdio.h> #include <math.h> using namespace std; class dot { double x; double y; public: void input(void); void output(void); }; void dot::input(void) { cout<<endl; cout<<"Input X="; cin>>x; cout<<"Input Y="; cin>>y; return; } void dot::output() { cout<<endl; cout<<"X="<<x<<endl; cout<<"Y="<<y<<endl; return; void bubblesort(dot *m, int size) { dot *t = new dot; for(int i=size; i>0; i--) for(int j=0; j<i-1; j++) if(m[j].gety() > m[j+1].gety()) { t=m[j]; m[j] = m[j+1]; m[j+1] = t; } delete t; } }
-
25th September 2016 20:33 #2
, , , - "" "".
"" n , vector<>, .
, :
1. n
2. n
3. "" / , /
4. ,
5. "" /,
/
? "" . , ..Last edited by hateras; 25th September 2016 at 20:33.
ASRock B550M Pro 4; Ryzen R5 3600; 2x16 GiB G.SKILL Aegis 3200; 1TB Samsung QVO 960 + 3TB Seagate IronWolf; Zalman Z1
-
1st October 2016 18:23 #3Registered User
Join Date: Sep:2016
Location: Bulgaria
Posts: 2
Code:#include <iostream.h> #include <stdio.h> class dot { double x; double y; public: void input(void); void output(void); friend void bubblesort(dot *m, int size); }; void dot::input(void) { cout<<endl; cout<<"Input X="; cin>>x; cout<<"Input Y="; cin>>y; return; } void dot::output() { cout<<endl; cout<<"X="<<x<<endl; cout<<"Y="<<y<<endl; return; } int n=0; dot *dots; void bubblesort(dot *m, int size) { for(int i=size; i>0; i--) for(int j=0; j<i-1; j++) if(m[j].y < m[j+1].y) { dot t = m[j]; m[j] = m[j+1]; m[j+1] = t; } } void SaveDots (int n,dot *current) // { FILE *fp; char name [30]; cout<<"Enter file name:"; cin>>name; fp=fopen (name,"wb"); // if (fp!=NULL) { // fputc(n,fp); fwrite (current, sizeof(dot), n, fp); fclose (fp); } else cout<<"Error record to file!"; } void ReadDots() // { FILE *fp; char name [30]; // cout<<"Enter file name:"; cin>>name; int n=0; fp=fopen(name, "rb"); // if (fp!=NULL) // { n=fgetc(fp); // . . dots = new dot[n]; // fread(dots,sizeof(dot),n,fp); // fclose(fp); // } else cout<<"\nFile not found"<<endl; } int main() { int a=0; do // - { cout<<"\nPlease select operation:"<<endl; cout<<"1 - Input"<<endl; cout<<"2 - Output"<<endl; cout<<"3 - Sort"<<endl; cout<<"4 - Save in file"<<endl; cout<<"5 - Read from file"<<endl; cout<<"Something else for exit"<<endl; cin>>a; switch(a) { case 1: { cout<<"Kolko to4ki 6te vuvejdate:"; cin>>n; dots= new dot[n]; for(int i=0;i<n;i++) { cout<<"\nInput dot "<<i+1<<" :"; dots[i].input(); } break; } case 2: // - { cout<<"Vuvedenite tochki sa:"<<endl; for(int j=0;j<n;j++) { cout<<"\nDot"<<j+1<<" : "; dots[j].output(); } break; } case 3: { bubblesort (dots,n); // cout<<"Sortiranite koordinati sa:"<<endl; for(int k=0; k<n; k++) { dots[k].output();// output() } break; } case 4: { SaveDots (n,dots); break; } case 5: { ReadDots (); cout<<"Prochetenite tochki sa:"<<endl; for(int w=0;w<n;w++) { cout<<"\nDot"<<w+1<<" : "; dots[w].output(); } break; } } } while(a>0 && a<6); return 0; }
? void ReadDots() SaveDots
warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.Last edited by feelthesound; 1st October 2016 at 19:30.




Reply With Quote
Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in