#include<iostream> using namespace std; struct Complex{ double real; double imaginary; }; int add(int a,int b); double add(double c,double d); Complex add(Complex e,Complex f); int main(){ int a,b; cout<<"请输入两个整型数字"<<endl; cin>>a>>b; double c,d; cout<<"请输入两个double型数字"<<endl; cin>>c>>d; Complex e,f; cout<<"请输入两个complex型数字"<<endl; cin>>e.real>>e.imaginary>>f.real>>f.imaginary; add(a,b); add(c,d); add(e,f); return 0; } int add(int a,int b) { cout<<a+b<<endl; } double add(double c,double d) { cout<<c+d<<endl; } Complex add(Complex e,Complex f) { cout<<e.real+f.real<<"+"<<e.imaginary+f.imaginary<<"i"<<endl; }
主函数
#include <iostream> #include "标头.h" using namespace std; int main() { int i; int a[5] = { 20,12,36,54,82 }; double b[5] = { 3.6,2.1,5.1,11.1,12.1 }; quick(a, 0, 5); quick(b, 0, 5); for (i = 0; i < 5; i++) cout << " " << a[i]; cout << endl; for (i = 0; i < 5; i++) cout <<" "<< b[i]; system("pause"); return 0; }
Quicksort
#ifndef Quicksort #define Quicksort template <class T> void quick(T s[], int low, int high) { int a, b, c = 0; T e, f; a = low; b = high - 1; e = s[(low + high) / 2]; if (a < b) { while (a < b) { while (a < b&&e < s[b]) b--; while (a < b&&e > s[a]) a++; if (a >= b) c = b; else { f = s[a]; s[a] = s[b]; s[b] = f; } } quick(s, low, c); quick(s, c + 1, high); } } #endif
#include<iostream> #include<string> using namespace std; class User { public: void setInfo(string name0,string passwd0 = "111111", string email0 = " "); void changePasswd(); void printInfo(); void changemail(); 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 passwd1, passwdN; int n=1; cout << "输入旧密码:"; cin >> passwd1; while (n <= 3) { if (User::passwd == passwd1) { cout << "输入新密码:"; cin >> passwdN; break; } else if(n<3&&(User::passwd != passwd1)) { cout << "输入错误,请再试一遍:"; cin >> passwd1; n++; } else if (n == 3 && (User::passwd != passwd1)) { cout << "请稍后再试." << endl; break; } } } void User::printInfo() { cout << "name:\t\t" << name << endl; cout << "passwd:\t\t" <<"******"<< endl; cout << "email:\t\t" << email << endl; } void User::changemail() { string emailN; char a = ‘@‘; string::size_type idx; cout << "Enter the new email:"; cin >> emailN; idx = emailN.find(a); while (idx == string::npos) { cout << "Add @ to your email:"; cin >> emailN; idx = emailN.find(a); } } int main() { cout << "testing 1......" << endl << 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(); user2.changemail(); system("pause"); return 0; }
https://www.cnblogs.com/lovecpp/p/10584507.html
https://www.cnblogs.com/linjiahao1035/p/10585993.html
https://www.cnblogs.com/bzwy/p/10564202.html
原文:https://www.cnblogs.com/Tiger-Hu22/p/10587997.html