实验二

#include <iostream> 
using namespace std; 
int add(int x,int y) 
{ return x+y; } 
double add(double x,double y) 
{ return x+y; } 

int add(int,int);
double add(double, double);
int main(){
    int x;
    double y;
    int a,b;
    cout<<"请输入两个整数:"<<endl;
    cin>>a>>b;
    x=add(a,b);
    cout<<"整数之和为:"<<x<<endl;
    double c,d;
    cout<<"请输入两个double型数:"<<endl; 
    cin>>c>>d;
    y=add(c,d);
    cout<<"double类型之和为:"<<y<<endl;
   return 0;

} 

  

#include <iostream>
#include<cstdlib>
#include<ctime>

using namespace std;
template<typename T>
void Quick_sort(T *data_ptr, int left, int right)
{
int low(left), high(right);
T middle, temp;

middle = data_ptr[(rand()%(right - left + 1)) + left]; 
do{
while ((data_ptr[low] < middle) && (low < right)) 
low++;

while ((data_ptr[high]) > middle && (high > left)) 
high--;


if (low <= high) 
{
temp = data_ptr[low];
data_ptr[low] = data_ptr[high];
data_ptr[high] = temp;
low++;
high--;
}

}while(low <= high); 


if (left < high)
Quick_sort(data_ptr, left, high); 


if (right > low)
Quick_sort(data_ptr, low, right);
}

int main()
{
int a[10];
 double b[10];
 char c[10] ;
 int i,j;
 cout<<"请输入10个整型数字"<<endl;
 for(i=0;i<=9;i++)
    cin>>a[i];
 cout<<"请输入10个double型数字"<<endl;
 for(i=0;i<=9;i++)
    cin>>b[i];

 cout<<"请输入10个char数字"<<endl;
 for(i=0;i<=9;i++)
    cin>>c[i];
  
 Quick_sort(a,0,9);
 for (i = 0; i < 9; i++)
cout << a[i] << " ";
cout << endl;
 Quick_sort(b,0,9);
 for (i = 0; i < 9; i++)
cout << b[i] << " ";
cout << endl;
 Quick_sort(c, 0, 9);
 for (i = 0; i < 9; i++)
cout << c[i] << " ";
cout << endl;
 return 0;
} 

属实我弄不出来。。。。=-=所以没有结果图

#include <iostream>
#include <string>
using namespace std;
class user 
{public:
   void setInfo(string name0,string password0="111111",string email0=" ");
   void changePassword();
   void printInfo();
 private:
   string name;
   string password;
   string email;
};

void user::setInfo(string name0,string password0,string email0)
{name=name0;
 password=password0;
 email=email0;
}

void user::changePassword()
{string old;
 int i=0;
 cout<<"请输入原密码:"<<endl;
 cin>>old;
 while (old!=password && i<2)
      {i++;
       cout<<"错误,请重新输入:"<<endl;
       cin>>old;
      }
 if(old==password)
   {cout<<"请输入新密码:"<<endl;
    cin>>password;
   }
 else if(i=2)
   cout<<"请稍后再试"<<endl;
}

void user::printInfo ()
{cout<<"name :"<<name<<endl;
 cout<<"passwd  : ******"<<endl;
 cout<<"email :"<<email<<endl;
}

int main() 
{user user1;
 user1.setInfo("Leonard");
 user1.printInfo();
 user1.changePassword();
 user1.printInfo();
 cout<<endl;
 user user2;
 user2.setInfo("Jonny","92197","xyz@hotmail.com");
 user2.printInfo();
 return 0;
}

 

posted on 2019-03-26 23:31  沐尘河  阅读(111)  评论(1编辑  收藏  举报

导航