#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; cout<<"输入两个整数:"; cin>>a>>b; cout<<add(a,b)<<endl; double c,d; cout<<"输入两个double型的数:"; cin>>c>>d; cout<<add(c,d)<<endl; complex g,e,f; cout<<"输入两个complex型的数:"; cin>>e.real>>e.imaginary>>f.real>>f.imaginary; g=add(e,f); cout<<g.real<<"+"<<g.imaginary<<"i"<<endl; return 0; }
#include <iostream> using namespace std; template<class T> void Quicksort(T a[],int m,int n) { int i=m, j=n-1; T t=a[i]; if(i<j) {while(i<j) { while(i<j&&a[j]>=t) j--; if(i<j) {a[i]=a[j];i++;} while(i<j&&t>a[i]) i++; if(i<j){a[j]=a[i];j--;} } a[i]=t; Quicksort(a,m,i); Quicksort(a,i+1,n); } } int main() { int i; int a[5]={11,33,55,22,31}; cout<<"a[5]={11,33,55,22,31}"<<endl; Quicksort(a,0,5); cout<<"按升序排序为:"; for(i=0;i<5;i++) cout<<a[i]<<" "; cout<<endl; double b[5]={1.9,1.7,3.4,4.3,2.1}; cout<<"b[5]={1.9,1.7,3.4,4.3,2.1}"<<endl; Quicksort(b,0,5); cout<<"按升序排序为:"; for(i=0;i<5;i++) cout<<b[i]<<" "; cout<<endl; return 0; }
#include<iostream> #include<string> using namespace std; class User{ public: void setInfo(string name0,string passwd0="111111",string email0=" "); void changePasswd(); void printInfo(); private: string name; string passwd; string email; }; void User::setInfo(string name0,string passwd0,string email0) { name=name0; passwd=passwd0; email=email0; } void User::changePasswd() { string passwd; int i=0; cout<<"请输入旧密码:"<<endl; cin>>passwd; while(passwd!="111111"&&i<3) {i++; cout<<"输入错误,请重新输一遍:"<<endl; cin>>passwd; } if(passwd=="111111") {cout<<"请输入你的新密码:"<<endl; cin>>passwd; cout<<"修改密码成功"<<endl; } else if(i==3) cout<<"请稍后再试"<<endl; } 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; }
原文:https://www.cnblogs.com/aiyy492903331/p/10604618.html