码迷,mamicode.com
首页 > 其他好文 > 详细

实验2

时间:2019-03-27 00:06:07      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:修改   while   技术   main   bsp   image   user   图片   nbsp   

#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 i = 1 , j = 2; double m = 1.0 , n = 2.0; Complex a , b; a.imaginary = 1.0 , a.real = 1.0; b.imaginary = 1.0 , b.real = 1.0; cout<<"输入i , j"<<endl; cin>>i>>j; int k = add(i , j); cout<<"a + b = "<<k<<endl; cout<<"输入m , n"<<endl; cin>>m>>n; double s = add(m , n); cout<<"m + n = "<<s<<endl; cout<<"输入a的imaginary和real值:"<<endl; cin>>a.imaginary>>a.real; cout<<"输入b的imaginary和real值:"<<endl; cin>>b.imaginary>>b.real; // cout<<"a + b = "<<endl; Complex c; c = add(a , b); cout<<"总和的imaginary为 "<<c.imaginary<<endl; cout<<"总和的real为 "<<c.real<<endl; return 0; } int add(int i , int j) { int k = i + j; return k; } double add(double m , double n) { double s; s = m + n; return s; } Complex add(Complex a , Complex b) { Complex c; c.imaginary = a.imaginary + b.imaginary; c.real = a.real + b.real; return c; }

  运行结果技术图片

2

#include <iostream>
using namespace std;
void qa(int a[],int n)
{
    int i=0,j=n-1;
    int m=a[0];
    if(n<=1)
    {
                return ;

     }
while(i<j)
     {
         for(;j>i;j--){
             if(a[j]<m)
             {
                 a[i++]=a[j];
                 break;
             }
}
         for(;i<j;i++)
         {
             if(a[i]>m)
             {
                 a[j--]=a[i];
                 break;
             }
         }
     }
        a[i]=m;
        qa(a,i);
        qa(a+i+1,n-i-1);
}
技术图片 
#include <iostream>
using namespace std;
void qa(int a[],int n)
{
    int i=0,j=n-1;
    int m=a[0];
    if(n<=1)
    {

                return ;

     }

     while(i<j)
     {
         for(;j>i;j--)
         {
             if(a[j]<m)
             {
                 a[i++]=a[j];
                 break;
             }

         }
         for(;i<j;i++)
         {
             if(a[i]>m)
             {
                 a[j--]=a[i];
                 break;
             }

         }

     }
        a[i]=m;
        qa(a,i);
        qa(a+i+1,n-i-1);
}

int main(void)
{
    int b[10];
    int i=0;
    cout<<"输入:";
    for(i=0;i<10;i++)
    {
        cin>>b[i];
    }
        qa(b,10);
        cout<<"输出: ";
        for(i=0;i<10;i++)
           cout<<" "<<b[i];
        return 0;
}

  运行结果技术图片

3

#include<iostream>
#include<cstring>
#include<string>
using namespace std;

class User
{
public:
    void setInfo(string name1 , string passwd1 , string email1);
    int setInfo(string name1);
    void changePasswd();
    void printInfo();
private:
    string name;
    string passwd;
    string email;
};
void User::setInfo(string name1 , string passwd1 , string email1)
{
    name.assign(name1);
    passwd.assign(passwd1);
    email.assign(email1);
}
int User::setInfo(string name1)    
{
    name.assign(name1);
    email.assign("");
    passwd.assign("111111");
    return 0;
}


void User::changePasswd()
{
    string oldpassword;
    string passwd1;
    cout<<"原密码: "<<endl;
    cin>>oldpassword;
    int n = 1;
    while(oldpassword != passwd)
    {
        if(n < 3)
        {
            int i = 3 - n;
            cout<<"错误,请重新输入密码"<<endl;
            cin>>oldpassword;
            n++;
        }
        else
        {
            cout<<"验证失败,请稍后再试,暂时退出修改密码程序"<<endl;
            return;
        }
    }
    cout<<"请输入新密码: "<<endl;
    cin>>passwd1;
    passwd.assign(passwd1);
    return;
}

void User::printInfo()
{
    cout<<"用户名: "<<name<<endl;
    cout<<"密码: "<<"******"<<endl;
    cout<<"邮箱: "<<email<<endl;
    return;
}

int main()
{
    
    User user1;
    user1.setInfo("first");
    user1.printInfo();
    user1.changePasswd();
    user1.printInfo();
    User user2;
    user2.setInfo("second" , "123456" , "126@126.com");
    user2.printInfo();
    return 0;
}

运行结果

技术图片

 

实验2

标签:修改   while   技术   main   bsp   image   user   图片   nbsp   

原文地址:https://www.cnblogs.com/hi-ypy/p/10604787.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!