实验2
Posted hi-ypy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了实验2相关的知识,希望对你有一定的参考价值。
#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" , "[email protected]"); user2.printInfo(); return 0; }
运行结果
以上是关于实验2的主要内容,如果未能解决你的问题,请参考以下文章
使用 React 实验性中继片段:缺少属性 '"$fragmentRefs"'
[NTUSTISC pwn LAB 7]Return to libc实验(puts泄露libc中gadget片段定位)