实验二

#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<<"Enter two integer"<<endl;
    cin>>a>>b;
    cout<<"Their sum of square:"<<add(a,b)<<endl;
    
    double m, n;
    cout<<"Enter two integer"<<endl;
    cin>>m>>n;
    cout<<"Their sum of square:"<<add(m,n)<<endl;
    
    Complex k,l;
    cout<<"Enter two integer"<<endl;
    cin>>k.real>>l.real>>k.imaginary>>l.imaginary;
    add(k,l);
    
    return 0;
    
}
int add(int x,int y){
    
    return (x+y);
}

double add(double q,double o){
    
    return (q+o);
}

Complex add(Complex s,Complex t){
    
    Complex u;
    
    u.real=s.real+t.real;
    
    u.imaginary=s.imaginary+t.imaginary;
    
    cout<<u.real<<"+"<<u.imaginary<<"i"<<endl;
    
    return u;
    
}

#include<iostream>
using namespace std;
void quicksort(int a[],int left, int right){
    int i,j,t,temp;
    if(left>right)
    return ;
    temp=a[left];
    i=left;
    j=right;
    while(i<j){
        while(a[j]>=temp&&i<j)
        j--;
        a[i]=a[j];
        while(a[i]<temp&&i<j)
        i++;
        a[j]=a[i];
    }
    a[i]=temp;
    quicksort(a,left,i-1);
    quicksort(a,i+1,right);
}
int main(){
    int  a[10]={98,89,78,56,65,15,26,63,26,36},i;
    quicksort(a,0,9);
    for(i=0;i<10;i++)
    cout<<a[i]<<" ";
    return 0;
}
#ifndef HEADER_quicksort_H
#define HEADER_quicksort_H

template<class T> 
void quicksort(T a[],int left, int right){
    int i,j,t;
    if(left>right)
    return ;
    T temp=a[left];
    i=left;
    j=right;
    while(i<j){
        while(a[j]>=temp&&i<j)
        j--;
        a[i]=a[j];
        while(a[i]<temp&&i<j)
        i++;
        a[j]=a[i];
    }
    a[i]=temp;
    quicksort(a,left,i-1);
    quicksort(a,i+1,right);
}
#endif
#include<iostream>
#include"quicksort.h" 
using namespace std;


int main(){
    int  a[10]={98,89,78,56,65,15,26,63,26,36},i;
    quicksort(a,0,9);
    for(i=0;i<10;i++)
    cout<<a[i]<<" ";
    return 0;
}

#include <iostream>
#include <string>
using namespace std;
// User类的声明
class User {
public:
void setInfo(string name0,string passwd0="111111",string email0="");// 声明带有默认形参值的成员函数setInfo()
// 密码默认值为6个1
// 邮箱默认值为空串
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 passwd1;
    int i;
    cout<<"请输入原密码:";
    cin>>passwd1;
    for(i=0;i<2&&passwd1!="111111";i++){
    cout<<"密码错误,请重新输入";        
        cin>>passwd1;    
        }    
        if(i>=2)
            cout<<"错误上限已达到,请稍后再试"<<endl; 
         else
         cout<<"请输入新密码:";    
}
void User::printInfo(){
    cout<<"name"<<name<<endl;
    cout<<"passwd"<<"******"<<endl;
    cout<<"email"<<endl;
}

int main() {
cout << "testing 1......" << endl;
// 测试1
User user1;
user1.setInfo("Leonard");
user1.printInfo();
user1.changePasswd();
user1.printInfo();
cout << endl << "testing 2......" << endl << endl;
// 测试2
User user2;
user2.setInfo("Jonny","92197","xyz@hotmail.com");
user2.printInfo();
return 0;
}

 

 

通过这次实验,发现了自身许多不足,

第一个实验中关于复数的加减一开始没有想到应该是实部加实部,虚部加虚部,第二个实验中,在创建项目时遇到困难,最后在同学的帮助下完成,第三个实验中一开始当输入三次错误密码后,输出的是密码错误请重新输入错误次数已达上限,请稍后再试,发现是自己if条件有错然后重新修改程序。

在实验中发现自己许多不足,以后会改正的。

 https://www.cnblogs.com/mzy-1229/p/10590910.html

 https://www.cnblogs.com/wmy0621/p/10590291.html

https://www.cnblogs.com/lyc1103/p/10580220.html

posted @ 2019-03-24 22:25  agsjg  阅读(107)  评论(2编辑  收藏  举报