标签:new -- 快速排序 std 基础 cout ... pass include
#include<iostream> using namespace std; struct Complex { double real; double imaginary; }; int add(int, int); double add(double,double); Complex add(Complex, Complex); int main() { int a,b,c; cin>>a>>b; c= add(a,b); cout<<c<<endl; double n,m,h; cin>>n>>m; h= add(n,m); cout<<h<<endl; Complex i,j,k; cin>>i.real>>i.imaginary>>j.real>>j.imaginary; k= add(i,j); cout<<k.real<<"+"<<k.imaginary<<endl; return 0; } int add(int a,int b) { return a+b; } double add(double n, double m) { return n+m; } Complex add(Complex i,Complex j) { Complex x; x.real=i.real+j.real; x.imaginary=i.imaginary+j.imaginary; return x; }
#include <iostream> using namespace std; int partition(int a[],int left,int right) { int i=left; int j=right; int temp=a[i]; while(i<j) { while(i<j && a[j]>=temp) j--; if(i<j) a[i]=a[j]; while(i<j && a[i]<=temp) i++; if(i<j) a[j]=a[i]; } a[i]=temp; return i; } double partition(double a[],int left,int right) { int i=left; int j=right; double temp=a[i]; while(i<j) { while(i<j && a[j]>=temp) j--; if(i<j) a[i]=a[j]; while(i<j && a[i]<=temp) i++; if(i<j) a[j]=a[i]; } a[i]=temp; return i; } void quickSort(int a[],int left,int right) { int m; if(left<right) { m=partition(a,left,right); quickSort(a,left,m-1); quickSort(a,m+1,right); } } void quickSort(double a[],int left,int right) { int m; if(left<right) { m=partition(a,left,right); quickSort(a,left,m-1); quickSort(a,m+1,right); } } int main() { int a[10]={12,44,74,86,45,99,64,23,48}; quickSort(a,0,9); for(int i=0;i<10;i++) { cout<<a[i]<<" "; } cout<<"\n"<<endl; double b[10]={1.2,4.4,7.4,8.6,4.5,9.9,6.4,2.3,4.8}; quickSort(b,0,9); for(int i=0;i<10;i++) { cout<<b[i]<<" "; } return 0; }
#include <iostream> #include <string> using namespace std; class User { public: void setInfo(string name4,string password4="111111",string email4=" "); void changePasswd(); void printInfo(); private: string name; string passwd; string email; }; void User:: setInfo(string name4,string password4,string email4) { name=name4; passwd=password4; email=email4; } void User::changePasswd(){ string oldpassword; cin>>oldpassword; int i=1; while(oldpassword!=passwd&&i<3) { cout<<"wrong,enter your old password anagin:"; cin>>oldpassword; i++; } if(i>=3) cout<<"try later"<<endl; if(oldpassword==passwd) { string newpassword; cin>>newpassword; passwd=newpassword; } } void User::printInfo(){ cout<<"name:"<<name<<endl; cout<<"password"<<"******"<<endl; cout<<"email:"<<email<<endl; } int main() { cout << "testing 1......" << endl; User user1; user1.setInfo("Leonard"); user1.printInfo(); user1.changePasswd(); user1.printInfo(); cout << endl << "testing 2......" << endl << endl; User user2; user2.setInfo("Jonny","92197","xyz@hotmail.com"); user2.printInfo(); return 0; }
实验总结:
本次实验相比上次难度提升了 但我在会使用快速排序法的基础上学会了用c++编写快速排序法。
标签:new -- 快速排序 std 基础 cout ... pass include
原文地址:https://www.cnblogs.com/mzx1999/p/10597319.html