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

实验二

时间:2019-03-27 00:24:14      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:name   info   img   void   eal   i++   4.6   oid   sort   

1

#include <iostream>
#include <complex>
using namespace std;
typedef complex<double>name;
struct Complex
{
 double real;
 double imaginary;
};
int add(int a, int b)
{return a+b;
}
double add(double a,double b)
{return a+b;
}
name add(name a, name b)
{return a+b;
}
int main() 
{int m,n;
 cout<<"Enter two integer:";
 m=2,n=5;
 cout<<"Their sum of square:"<<add(m,n)<<endl;
 
 double x,y;
 cout<<"Enter two integer:";
 x=12.4;y=2.1;
 cout<<"Their sum of square:"<<add(x,y)<<endl;
 
 name i,j;
 cout<<"Enter two integer:";
 i=1+2i;j=3+6i;
 cout<<"Their sum of square:"<<add(i,j)<<endl;

 return 0;
}

技术图片

2

#include<iostream>
using namespace std;
template<typename T>
void QuickSort(T i[],int left,int right)
{if(left<right)
    {int low=left;
     int high=right;
     T x=i[low]; 
     while(low<high)
     {while(low<high&&i[high]>x)high--; 
      if(low<high)
      {i[low]=i[high];
       low++;
      } 
     while(low<high&&i[low]<x)low++;
     if(low<high)
     {
      i[high]=i[low];
      high--; 
      }
     }
        i[low]=x;
        QuickSort(i,left,low-1);
        QuickSort(i,low+1,right);
    }
}
int main()
{
    int i;
    int a[10]={6,54,51,34,8,38,24,74,10,2};
    cout<<"a[10]={6,54,51,34,8,38,24,74,10,2}"<<endl;
    QuickSort(a,0,9);
    cout<<"before:"<<endl;
    for(i=0;i<10;i++)
    cout<<a[i]<<ends;
    cout<<endl;
    float b[10]={5.3,4.2,8.2,7.3,6.2,1.9,9.4,4.6,3.2,5.4};
    cout<<"b[10]={5.3,4.2,8.2,7.3,6.2,1.9,9.4,4.6,3.2,5.4}"<<endl;
    cout<<"after:"<<endl;
    QuickSort(b,0,9);
    for(i=0;i<10;i++)
    cout<<b[i]<<ends;
    return 0;
}

技术图片

3

#include <iostream>
#include <string> 
using namespace std;
class user{
 public:
     user(){};
     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()
{int c=1;
 string passwd1;
 cout<<"please enter the old passward:\n";
 cin>>passwd1;
 while(passwd1!=passwd)
 {cout<<"Password error, Please enter again:\n";
  c++;
  cin>>passwd1;
  if(c>3)
  cout<<"You have entered three errors in a row, please try later!\n";
 }
 cout<<"Please enter a new password:\n";
 cin>>passwd1;
 passwd=passwd1;
}
void user::printinfo()
{cout<<"name:"<<name<<endl;
 cout<<"passwd:******"<<endl;
 cout<<"email:"<<email<<endl;
}
int main()
{cout<<"testing1..."<<endl;
  user user1;    
  user1.setinfo("Leonard");  
  user1.printinfo(); 
  user1.changepasswd(); 
  user1.printinfo();
  cout<<endl<<"testing2..."<<endl<<endl;
  user user2;
  user2.setinfo("Jonny","92197","xyz@hotmail.com"); 
  user2.printinfo(); 
  return 0;
}

技术图片

 

 求助了同学怎么做,还是有地方不太会,可能还是熟练度不够

实验二

标签:name   info   img   void   eal   i++   4.6   oid   sort   

原文地址:https://www.cnblogs.com/changtingzao/p/10604741.html

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