第三周作业

来源:互联网 发布:mac开机显示问号文件夹 编辑:程序博客网 时间:2024/06/05 18:36

例题2.1

变化一:
// 2323.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <iostream>#include <iomanip>using namespace std;int main(){bool flag = true;cout<<flag<< endl;cout<<boolalpha<<flag<< endl;cout<<flag + 8<< endl;flag = NULL;cout<<"执行语句 flag = 0;后flag的值为:"<<boolalpha << flag << endl;flag = 0.0;cout<<"执行语句 flag = 0.0;后flag的值为: "<<boolalpha << flag<< endl;return 0;}


变化二:
// 2323.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <iostream>#include <iomanip>using namespace std;int main(){bool flag = true;cout<<flag<< endl;cout<<boolalpha<<flag<< endl;cout<<flag + 8<< endl;flag = 10;cout<<"执行语句 flag = 0;后flag的值为:"<<boolalpha << flag << endl;flag = 0.0;cout<<"执行语句 flag = 0.0;后flag的值为: "<<boolalpha << flag<< endl;return 0;}


例题2.2

变化一:

// 2323.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <iostream>using namespace std;int main(){int a,b,c,d;a = 4;b = a;a = 5;c = d = 6;    c = c * a;d = d % (a + b);cout<<"a = "<<a<<endl<<"b = "<<b<<endl<<"c = "<<c<<endl<<"d = "<<d<<endl;return 0;

变化二:
// 2323.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <iostream>using namespace std;int main(){int a,b,c,d;a = 4;b = a;a = 5;c = d = 6;    c -= a;d *= (a + b);cout<<"a = "<<a<<endl<<"b = "<<b<<endl<<"c = "<<c<<endl<<"d = "<<d<<endl;return 0;

例题2.3

变化一:
// 2323.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <iostream>using namespace std;int main(){long i,j,m,n;i=1000;j=1000;m=i+j;n=i*j;cout<<"m="<<m<<endl;cout<<"n="<<n<<endl;return 0;}

变化二:
// 2323.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <iostream>using namespace std;int main(){short i,j,m,n;i=100;j=100;m=i+j;n=i*j;cout<<"m="<<m<<endl;cout<<"n="<<n<<endl;return 0;}

例题2.4

变化一:
// 2323.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <iostream>using namespace std;int main(){    int i=6,j,k,temp;j=++i;k=i++;cout<<"i="<<i<<endl<<"j="<<j<<endl<<"k="<<k<<endl;return 0;}

变化二:
// 2323.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <iostream>using namespace std;int main(){    int i=6,j,k,temp;j=i--;k=--i;--i=2;cout<<"i="<<i<<endl<<"j="<<j<<endl<<"k="<<k<<endl;return 0;}

例题2.5

变化一:

// qwqwqwq.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <iostream>using namespace std;int main(){char ch;cout<<"plaese input a character:";cin>>ch;ch = ch>='a'&&ch<='z'?ch-'a'+'A':ch;    cout<<"The result is:"<<ch<<endl;return 0;}

变化二:
// qwqwqwq.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <iostream>using namespace std;int main(){char ch;cout<<"plaese input a character:";cin>>ch;ch = ch>='a'&&ch<='z'?ch-32:ch;    cout<<"The result is:"<<ch<<endl;return 0;}

例题2.6



0 0
原创粉丝点击