#include<iostream>
using namespace std;struct complex { double real; double imaginary;};int add(int a, int b){ return a + b;}double add(double a, double b){ return a / b;}complex add(complex a, complex b){ complex s; s.imaginary = a.imaginary + b.imaginary; s.real = a.real + b.real; return s;}int main(){ complex a = { 2.3,3.2 }; complex b = { 4.5,5.4 }; complex c = add(a, b); cout << "1+2=" << add(1, 2) << endl; cout << "2.2/1.1=" << add(2.2, 1.1) << endl; cout << "complex ab=" << c.real << "," << c.imaginary << endl; system("pause"); return 0;}#include<iostream>
using namespace std;template<class X>X Quicksort(X a[], int low, int high){ if (low >= high) { return 0; } int x = low; int y = high; int key = a[x]; while (x < y) { while (a[y] >= key && x < y) { --y; } a[x] = a[y]; while (a[x] <= key && x < y) { ++x; } a[y] = a[x]; } a[x] = key; Quicksort(a, low, x - 1); Quicksort(a, x + 1, high);}int main(){ int i, a[5] = { 1,6,2,9,5 }; Quicksort(a, 0, 5); for (i = 1; i < 6; i++) cout << a[i] << " "; system("pause"); return 0;}#include <iostream>
#include <string>using namespace std;class User { public: void setinfo(string name1 = "", string passwd1 = "12345", string email1 = ""); void changepasswd(); void printinfo();private: string name; string passwd; string email;};void User::setinfo(string name1, string passwd1, string email1) { name = name1; passwd = passwd1; email = email1;}void User::changepasswd() { string old; int i = 0; do { cout << "请输入原密码:"; cin >> old; if (old == passwd) { cout << "请输入修改后的密码:"; cin >> passwd; cout << "修改成功!"; break; } else i++; if (i == 3) cout << "连续三次输错,请稍后重试!"; } while (i != 3);}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 << "testing 2......" << endl; User user2; user2.setinfo("Jonny", "92197", "xyz@hotmail.com"); user2.printinfo(); system("pause"); return 0;}