c++实验二

using namespace std;
struct Complex {
	double real;
	double imaginary;
};
int add(int a,int b); 
double add(double m,double n);
Complex add(Complex x,Complex y);
int main()
  { int s1;
    double s2; 
    Complex s3;
    int a,b;
	cout<<"输入两个整数"<<endl;
	cin>>a>>b;
	s1=add(a,b); 
    cout<<"两个整数之和为"<<s1<<endl;
    double m,n;
	cout<<"输入两个数"<<endl;
	cin>>m>>n;
	s2=add(m,n);
	cout<<"两数之和为"<<s2<<endl;
	Complex x,y;
	cout<<"输入两个复数的实部和虚部"<<endl;
	cin>>x.real>>x.imaginary>>y.real>>y.imaginary;
	s3=add(x,y);
	cout<<"两个复数之和为"<<s3.real<<"+"<<s3.imaginary<<"i"<<endl;
	return 0; 
   }
int add(int a,int b)
  { return a+b;
  }  
double add(double m,double n)
  { return m+n;
  }
Complex add(Complex x,Complex y)
  {  Complex s3;
     s3.real=x.real+y.real;
     s3.imaginary=x.imaginary+y.imaginary;
     return s3;
  }

 

#include <iostream>
using namespace std;
#include <iomanip>
#include "sort.h"
using namespace std;
int main ()
{int i;
 int a[5]={2,36,48,74,46 };
 double b[5]={12.5,3.8,2.8,4.9,3.1};
 sort(a,0,5);
 sort(b,0,5);
 for (i=0;i<=4;i++)
   cout<<setw(5)<<a[i]<<endl;
 for (i=0;i<=4;i++)
   cout<<setw(6)<<b[i]<<endl;
 return 0;
}


#ifndef Quicksort_H
#define Quicksort_H
template <class T>
void sort(W s[], int low, int high) {
    int a, b, c = 0;
    W J, sj;
    a = low; b = high - 1; J = s[(low+high)/2];
    if (a < b) {
    while (a < b) {
        while (a < b&&f < s[b])
            b--;
        while (a < b&&f > s[a])
            a++;
        if (a >= b) c = b;
        else { ex = s[a]; s[a] = s[b]; s[b] = ex; }
    }
        sort(s, low, c);
        sort(s, c + 1, high);
    }
}
#endif

  

 

#include <string>
using namespace std;
class User{
	public:
		void setInfo(string name1,string password1="111111",string email1=" ");
		void changePassword();
		void printInfo();
    private:
    string name;
    string password;
    string email;
};
void User::setInfo(string name1,string password1,string email1)
{ name=name1;
  password=password1;
  email=email1;
}
void User::changePassword()
{ string oldpassword;
  int i;
  cout<<"please enter your oldpssword"<<endl;
  cin>>oldpassword;
  while(oldpassword!=password && i<=3)
       {i++;
        cout<<"Sorry!Try again later."<<endl;
        cin>>password;
	   }
	   if(oldpassword==password)
	   {string newpassword;
	    cout<<"Please enter your newpassword"<<endl;
	    cin>>newpassword;
	    password=newpassword;
		} 
}
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.changePassword();
    user1.printInfo();
    cout<<endl<<"testing 2......"<<endl<<endl;
    User user2;
    user2.setInfo("Jonny","92197","Fairy@hotmain.com");
    user2.printInfo();
    return 0;
}

 

 https://www.cnblogs.com/qsxsc/p/10541028.html

https://www.cnblogs.com/suifeng823/p/10588507.html

 

 https://www.cnblogs.com/fearless04/p/10590986.html

 

posted @ 2019-03-24 15:18  小眉毛  阅读(166)  评论(2编辑  收藏  举报