北邮信通C++上机实验 第六章

合集下载

北邮通信原理实验报告完整

北邮通信原理实验报告完整

北京邮电大学通信原理课程实验实验报告学院:电子工程学院专业:电子信息科学与技术班级:2010211203班学号:姓名:2013年6月3日实验二抑制载波双边带的产生一、实验目的1.了解抑制载波双边带(SC-DSB)调制器的基本原理。

2.测试SC-DSB 调制器的特性。

二、实验步骤1.将TIMS 系统中的音频振荡器(Audio Oscillator)、主振荡器(Master Signals)、缓冲放大器(Buffer Amplifiers)和乘法器(Multiplier)按下图连接。

图1 实验连接图方式一2.用频率计来调整音频振荡器,使其输出为1kHz 作为调制信号,并调整冲放大器的K1,使其输出到乘法器的电压振幅为1V。

3.调整缓冲放大器的K2,使主振荡器输至乘法器的电压为1V 作为载波号。

4.测量乘法器的输出电压,并绘制其波形。

如下图2所示。

图2 乘法器输出电压波形5.调整音频振荡器的输出,重复步骤4。

如下图3所示。

图3 调整后输出波形6.将电压控制振荡器(VCO)模快和可调低通滤波器(Tuneable LPF)模块按下图4连接。

图4 实验连接图方式二7.VCO 得频率选择开关器至于“LO”状态下,调整VCO 的Vin(控制电压DC -3V~3V )使VCO 的输出频率为10kHZ。

8.将可调低通滤波器的频率范围选择范围至“wide”状态,并将频率调整至最大,此时截至频率大约在12kHz 左右。

LPF 截止频率最大的时候输出如图5所示。

图5 截止频率最大时输出9.将可调低通滤波器的输出端连接至频率计,其读数除360 就为LPF 的3dB 截止频率。

10.降低可调LPF 的截止频率,使SC-DSB 信号刚好完全通过低通滤波器,记录此频率(fh=fc+F)。

11.再降低3dB 截止频率,至刚好只有单一频率的正弦波通过低通滤波器,记录频率(fl=fc-F)只通过单一频率的LPF 输出如图6所示。

图6 单一低通滤波器输出12.变化音频振荡器输出为频率为800Hz、500Hz,重复步骤10、11,得到的波形如图7和8所示。

C语言程序设计教程第6章_北京邮电大学出版社

C语言程序设计教程第6章_北京邮电大学出版社

2013/7/9
C语言程序设计教程
11
[案例6-3] 定义一个函数,用于求两个数中的大数。 /*功能:定义一个求较大数的函数并在主函数中调用*/ int max(int n1, int n2) /*定义一个函数max()*/ { return (n1>n2?n1:n2); } main() { int max(int n1, int n2); /*函数说明*/ int num1,num2; printf("input two numbers:\n"); scanf("%d%d", &num1, &num2); printf("max=%d\n", max(num1,num2)); }
2013/7/9
C语言程序设计教程
20
2.函数类型
在定义函数时由类型标识符确定对函数类型的说明,应 与return语句中返回值表达式的类型一致。
如果不一致,则以函数类型为准,自动将数据转换成函 数的类型。如果缺省函数类型,则系统一律按整型处理。
案例6-4 返回值类型与函数类型不同
#include <stdio.h> void main() 输入:4.3 2.6 ↙ { int max(float,float); float a,b; 结果:Max is 4 scanf("%f%f",&a,&b); printf("Max is %d\n",max(a,b)); } int max(float x,float y) { return x>y?x:y; } 2013/7/9 C语言程序设计教程
(2)void类型的函数和有返回值类型的函数在定义时没 有区别,只是在调用时不同。 有返回值的函数可以将函数调用放在表达式中间,将返 回值用于计算。 而void类型的函数不能将函数调用放在表达式当中,只 能在语句中单独使用。 (3)void类型的函数多用于完成一些规定的操作,而主 调函数本身不再对被调函数的执行结果进行引用这样 就禁止在调用函数中使用被调函数的返回值。

北邮 C++计算机实习报告

北邮 C++计算机实习报告

计算机实习报告一.功能说明1.1总体功能说明本工程用C++语言实现了俄罗斯方块经典游戏。

俄罗斯方块游戏特点:俄罗斯方块的基本规则是通过键盘控制移动、旋转和摆放游戏自动输出的各种方块,使之排列成完整的一行或多行并且消除得分,上手简单,是一款经典游戏。

在经典玩法(正常模式)的基础上,本程序还添加了挑战模式,即在游戏伊始时在游戏区域中随机分布方块,减小了留给玩家调整方块的时间和区域,需要通过玩家不断填补消行才能把游戏进行下去。

游戏会随着玩家的得分的增多而加大方块下落的速度,从而增加游戏难度,因此也在原来的基础上大大增加了游戏的可玩性。

游戏中还增加了Esc键的功能,从而可以实现暂停游戏和退出游戏的功能。

1.2用户界面这是游戏的初始界面。

出现游戏名,根据提示,玩家按下“c”“n”即可自行选择挑战模式和正常模式,难度不同。

这样既明确了游戏名称,提供两种模式的入口,又给玩家一个准备的时间以自行控制游戏开始,不必一打开文件就突然开始游戏,增加了游戏的人性化。

以上两图为进入游戏后的主界面,分别为正常模式和挑战模式。

中间的区域为游戏主要界面,游戏从上往下随机产生并自动输出七种方块,对俄罗斯方块的基本操作如←(左移),→(右移),↑(方块变形),↓(加速下落)都在此区域里完成。

最上方显示的是模式。

右边的区域显示一些与游戏相关的信息,从上往下分别是下落速度、游戏得分、游戏操作说明,编者信息。

此图为按下“Esc”键后出现的画面。

程序支持Esc键暂停的功能,即按下后,按Y键退出,按N键可继续游戏,玩家中途有事离开,回来后也可继续游戏,提供了方便。

1.3使用方法打开程序后根据屏幕上的提示信息,按下回车键以进入游戏界面开始游戏。

进入游戏界面后,根据屏幕右下方的游戏说明,通过键盘上←(左移),→(右移),↑(方块变形),↓(加速下落)控制方块。

游戏过程中,可按“Esc”键暂停,并可以通过“Y”和“C”键选择退出和继续。

游戏结束之后,通过键盘按键“Y”和“N”选择是否退出游戏。

北邮通信原理实验报告

北邮通信原理实验报告

北京邮电大学通信原理实验报告学院:信息与通信工程学院班级:姓名:姓名:实验一:双边带抑制载波调幅(DSB-SC AM)一、实验目的1、了解DSB-SC AM 信号的产生以及相干解调的原理和实现方法。

2、了解DSB-SC AM 信号波形以及振幅频谱特点,并掌握其测量方法。

3、了解在发送DSB-SC AM 信号加导频分量的条件下,收端用锁相环提取载波的原理及其实现方法。

4、掌握锁相环的同步带和捕捉带的测量方法,掌握锁相环提取载波的调试方法。

二、实验原理DSB 信号的时域表达式为()()cos DSB c s t m t tω=频域表达式为1()[()()]2DSB c c S M M ωωωωω=-++其波形和频谱如下图所示DSB-SC AM 信号的产生及相干解调原理框图如下图所示将均值为零的模拟基带信号m(t)与正弦载波c(t)相乘得到DSB—SC AM信号,其频谱不包含离散的载波分量。

DSB—SC AM信号的解调只能采用相干解调。

为了能在接收端获取载波,一种方法是在发送端加导频,如上图所示。

收端可用锁相环来提取导频信号作为恢复载波。

此锁相环必须是窄带锁相,仅用来跟踪导频信号。

在锁相环锁定时,VCO输出信号sin(2πf c t+φ)与输入的导频信号cos(2πf c t)的频率相同,但二者的相位差为(φ+90°),其中很小。

锁相环中乘法器的两个输入信号分别为发来的信号s(t)(已调信号加导频)与锁相环中VCO的输出信号,二者相乘得到[A C m(t)cos(2πf c t)+A p cos(2πf c t)]∙sin(2πf c t+φ)=A c2m(t)[sinφ+sin(4πf c t+φ)]+A p2[sinφ+sin(4πf c t+φ)]在锁相环中的LPF带宽窄,能通过A p2sinφ分量,滤除m(t)的频率分量及四倍频载频分量,因为很小,所以约等于。

LPF的输出以负反馈的方式控制VCO,使其保持在锁相状态。

北邮信通C++上机实验 第七章

北邮信通C++上机实验 第七章

第七章实验题一.基础题1.#include <iostream>using namespace std;class CSample {double a;CSample(){a=2.5;};public:CSample(int val);~CSample(); };2.#include <iostream>using namespace std;class cube{public:cube();//构造函数~cube();//析构函数int volume(); //定义整形函数private:int height, width, depth;//定义私有数据成员};cube::cube(){height = 100;depth = 4;width = 2;cout<<"Constructor called."<<endl;}cube::~cube(){cout << "Destructor called." << endl;system("pause");}int cube::volume(){return height*width*depth;}void main(){cube cubeone; //定义对象cout<<"立方体的体积为:"<<cubeone.volume()<<endl;system("pause");}3.#include <iostream>using namespace std;class CCounter{int value;public:CCounter(){cout << "CCounter Constructor1" << endl;value = 0;}CCounter(int val){cout << "CCounter Constructor2" << endl;value = val;}~CCounter(){cout << "CCounter Destructor" << endl;system("pause");}};class CExample{int value;public:CCounter car;CExample(){cout << "CExample Constructor1" << endl;value = 0;}CExample(int val){cout << "CExample Constructor2" << endl;value = val;}~CExample(){cout << "CExample Destructor" << endl;system("pause");}void Display() { cout << "value=" << value << endl; } };void main(){CExample obj(350);obj.Display();system("pause");}//调用顺序:CCounter()-CExample(int val)-~CExample()-~CCounter()4.#include <iostream>using namespace std;class Point{protected:int x;public:int Getx(){ return x; }int Y;void init(int a, int b){ x = a; Y = b; } int Gety(){ return Y; }void Setx(int a){ x = a; }void Sety(int b){ Y = b; }};void main(){Point A, B;A.init(25, 27);B.init(29, 31);cout << "A.x=" << A.Getx() << endl;cout << "B.x=" << B.Getx() << endl;cout << "A.Y=" << A.Y << endl;cout << "A.y=" << A.Gety() << endl;cout << "B.y=" << B.Y << endl;cout << "B.y=" << B.Gety() << endl;system("pause");}5.#include <iostream>using namespace std;class base{private:int i;static int k; //定义静态变量k public:base() { i = 0; k++; } //定义构造函数void Display();};void base::Display(){k = k + 10;i++;cout << "i=" << i << ",k=" << k << endl; }int base::k = 0; //初始化k的值void main(){base a, b;a.Display();b.Display();system("pause");}运行结果为:i=1;k=12i=1;k=22二.编程题1.{if (x > 0){cout << "It's a positive number" << endl;positive++;}else if (x == 0){zero++;cout << "It's zero" << endl;}else{negative++;cout << "It's a negative number" << endl;}}int num::positive = 0; int num::negative = 0; int num::zero = 0; void main(){int n;while (cin >> n){num test(n);test.decision();test.print();}system("pause"); }2.#include <iostream>using namespace std;class dianqi{public:void getprice(int x , int y, int z ) {colorcast = x;ridge = y;washer = z;};void total(int a , int b , int c ){int t = a*colorcast + b*ridge + c*washer;cout << t << endl;};private:int colorcast;int ridge;int washer;};void main(){dianqi dian;dian.getprice(4200, 2800, 1500);cout << "请分别输入彩电,冰箱,洗衣机的销售数量:";int a = 0, b = 0, c = 0;cin >> a;cout << " ";cin >> b;cout << " ";cin >> c;cout << endl;cout << "总营业额为:";dian.total(a, b, c);system("pause");}3.#include<iostream>#include<string>using namespace std; class car{public:void disp_parameters(){cout << "型号:" << type<< endl;cout << "颜色:" << colour << endl;cout << "车门数:" << door << endl;cout << "座位数:" << seat << endl;cout << "轴距:" <<distance << endl;}void change(string a, char b, int c, int d, int e) {type = a;colour = b;door = c;seat = d;distance = e;}private:string type;char colour;int door;int seat;int distance;};void main(){car gundam;gundam.change("Double O GUNDAM", 'b', 1, 5, 6);gundam.disp_parameters();system("pause");}4.#include <iostream>using namespace std;class student{public:int num;char name[20];char sex;int age;};void main(){student stu[5];student temp;for (int i = 0; i<5; i++){cout << "输入第" << i + 1 << "位学生的学号:";cin >> stu[i].num;cout << "输入第" << i + 1 << "位学生的姓名:";cin >> stu[i].name;cout << "输入第" << i + 1 << "位学生的性别:";cin >> stu[i].sex;cout << "输入第" << i + 1 << "位学生的年龄:";cin >> stu[i].age;}for (int a = 1; a < 5; a++){for (int b =0 ; b < 5-a; b++){if (stu[b].age<stu[b + 1].age){temp.age = stu[b + 1].age;stu[b + 1].age = stu[b].age;stu[b].age = temp.age;}}}for (int i = 0; i<5; i++)cout << "num:" << stu[i].num << " name:" << stu[i].name << " sex:" << stu[i].sex << " age:" << stu[i].age << endl;system("pause");}5.#include <iostream>using namespace std;class ATM{public:void s_balance(void){cout << "The balance is " << balance << endl;}void deposit(float a){balance += a;}void withdraw(float a){balance -= a;}int checking(int a){if (key == a)return 1;elsereturn 0;}private:int key = 328;static float balance; };float ATM::balance = 0.0f; void main(){ATM sys1;int k,m;float num;cout << "Please input the key: ";cin >> k;if (sys1.checking(k) != 1)cout << "Error" << endl;else{cout << "Please choose the function:" << endl << "(1) Depositing money" << endl <<"(2) Withdrawing money" << endl <<"(3) Check the balance" << endl <<"(4) Return to the main interface"<<endl;while (cin >> m){switch (m){case 1:cout << "Please input how much you want to deposit: ";cin >> num;sys1.deposit(num);cout << "You have deposited " << num << endl;sys1.s_balance();cout << "Please choose the function:" << endl <<"(1) Depositing money" << endl <<"(2) Withdrawing money" << endl <<"(3) Check the balance" << endl << "(4) Return to the main interface" << endl;break;case 2:cout << "Please input how much you want to withdraw: ";cin >> num;sys1.withdraw(num);cout << "You have withdrawed " << num << endl;sys1.s_balance();cout << "Please choose the function:" << endl <<"(1) Depositing money" << endl <<"(2) Withdrawing money" << endl <<"(3) Check the balance" << endl << "(4) Returnto the main interface" << endl;break;case 3:sys1.s_balance();cout << "Please choose the function:" << endl <<"(1) Depositing money" << endl <<"(2) Withdrawing money" << endl <<"(3) Check the balance" << endl << "(4) Return to the main interface" << endl;break;case 4:cout << "Please choose the function:" << endl <<"(1) Depositing money" << endl <<"(2) Withdrawing money" << endl <<"(3) Check the balance" << endl;break;default:cout << "Error1" << endl;break;}}}system("pause"); }6.#include <iostream>#include<string>using namespace std;class student{public:friend void sort(student &a, student &b, student &temp);void change(string a, int b, float c){name=a;num = b;score = c;}float show(){return score;}private:int num;string name;float score;};void sort(student &a, student &b,student &temp){if (a.score < b.score){temp = a;a= b;b = temp;}}void main(){student stu[5];student temp;string q=" ";int w = 0;float e=0.0f;for (int i = 0; i<5; i++){cout << "输入第" << i + 1 << "位学生的姓名,学号,成绩:"<<endl;cout << " 姓名:";cin >> q;cout << " 学号:";cin >> w;cout << " 成绩:";cin >> e;stu[i].change(q, w, e);cout << endl;}for (int i = 1; i<5; i++){for (int j = 0; j<(5 - i); j++){sort(stu[j], stu[j + 1], temp);}}cout << "最高分" << stu[0].show() << endl;cout << "最低分" << stu[4].show() << endl;system("pause");}。

重庆邮电大学c语言上机实验期末实验报告

重庆邮电大学c语言上机实验期末实验报告

C语言程序实验报告姓名:班级:学号:学院:自动化第一章熟悉c语言编程环境实验目的及要求(1)了解c语言编程环境visual c++6.0的组成。

(2)了解并掌握c语言集成开发环境visual c++6.0的使用方法(3)了解并掌握c语言程序的基本结构,能够编写简单的程序(4)掌握c语言程序的上机步骤实验步骤:例1-1:编写一个简单的c语言程序,在屏幕上显示:”Hello World!”。

#include<stdio.h>void main(){printf("Hello World!\n");}实习题目1.41.写出下面程序执行结果。

#include<stdio.h>void main(){printf("我可以写c语言程序了!\n");}2编写c程序#include<stdio.h>void main(){printf("*\n");printf("**\n");printf("***\n");}第二章简单c语言程序设计实验目的及要求(1)进一步熟悉并掌握visual c++6.0集成开发环境的使用(2)熟练掌握c语言程序上机编写的步骤(3)掌握算术表达式、赋值表达式的使用(4)掌握c语言输入、输出函数的使用(5)能够编写简单的c语言程序(6)掌握简单c语言程序的差错方法实验步骤:例2-1:已知两个变量a、b,其值分别为100和200,编程求它们的和sum。

#include<stdio.h>void main(){int a,b,SUM;a=100;b=200;SUM=a+b;printf("他们的和是%d\n”,SUM);}例2-2已知一个圆柱体的半径r为6,高h为7,编写程序求圆柱体的体积。

#include<stdio.h>void main(){float r,h;float s;float v;r=6.0;h=7.0;s=3.14*r*r;v=s*h;printf("圆柱体的体积为%f\n",v);}2.4实习题目1写程序结果#include<stdio.h>void main(){int a;float b;a=4;b=9.5;printf("a=%d,b=%4.2f\n",a,b);}2已知直角三角形的两个直角边长分别为3、4,求此直角三角形的斜边长c及面积s。

北邮C++编程实验 第六章的内容

北邮C++编程实验  第六章的内容

6.3 实验题一、基础题1.分析下列程序,然后根据运行结果补充和修改一些语句,使之输出如图6-1的结果(已修改)#include<iostream>using namespace std;void main(){int a=20,b=40,c=60,temp;int &x=a,&y=b,&z=c;int *p1,*p2,*p3;p1=&a;p2=&b;p3=&c;temp=*p1;*p1=*p3;*p3=temp;cout<<endl;cout<<"一、用指向变量的指针形式输出该变量的地址:"<<endl;cout<<" "<<endl;cout<<" (1) 变量a的地址为:"<<&a<<endl;cout<<" (2) 变量b的地址为:"<<&b<<endl;cout<<" (3) 变量c的地址为:"<<&c<<endl;cout<<endl<<endl;cout<<"二、用变量的别名输出该变量的值:"<<endl;cout<<" "<<endl;cout<<" (1) 变量a的值为:"<<a<<" "<<"a的别名的值为:"<<x<<endl;cout<<" (1) 变量a的值为:"<<a<<" "<<"b的别名的值为:"<<y<<endl;cout<<" (1) 变量a的值为:"<<a<<" "<<"c的别名的值为:"<<z<<endl;}图6-1 第1题的输出示例2.在下列程序中填上适当的语句,完成输出最大和最小值的功能。

北邮c++实验6 绝对原创

北邮c++实验6 绝对原创

C++第六章实验课作业1、从键盘上输入一个整数,将该数插入到已知数组的合适位置,并分别打印插入前和插入后的数组程序代码:#include<iostream>using namespace std;void main(){int a[10]={6,12,34,56,78,89,90,409,800,2300},z,b[11],*pi,j;cout<<"请输入一个整数:";cin>>z;pi=a;cout<<"插入前的数组为:"<<endl;for(int i=0;i<10;i++)cout<<*(pi+i)<<' ';for(int i=0;i<10;i++){if(*(pi+i)<=z)b[i]=a[i];else {b[i]=z;j=i;break;}}cout<<"\n插入后的数组为:"<<endl;for(int i=0;i<11;i++){if(i>j) b[i]=a[i-1];cout<<b[i]<<' ';}}运行结果:2、用字符指针数组将给定的多个字符串(可以是任意5个国家的名字)进行排序并输出程序代码:#include<iostream>#include<string.h>using namespace std;void main(){char* country[5],*num;for(int i=0;i<5;i++){cout<<"输入任意五个国家名:"<<endl; char name[5][10];cin.getline(name[i],10,'\n');country[i]=name[i];}cout<<"排序后:"<<endl;for(int i=0;i<5;i++){for(int p=i+1;p<5;p++)for(int j=0;j<10;j++){if(*(country[i]+j)<*(country[p]+j)) break;else if(*(country[i]+j)>*(country[p]+j)) {num=country[i];country[i]=country[p];country[p]=num;break;}else continue;}cout<<country[i]<<endl;}}运行结果:3、已知有3名学生及五门课程的成绩,要求根据输入的编号及课程号输出该学生此门课程的成绩程序代码:#include<iostream>using namespace std;void main(){int a,b;struct stu{int num;char name[10];int grades[5];}s1={1,"诗诗",89,87,92,90,77},s2={2,"李博",100,77,89,86,90},s3={3,"猪猪",88,90,92,89,80};stu *come[3];come[0]=&s1;come[1]=&s2;come[2]=&s3;cout<<"请输入学生编号和课程号:"<<endl;cin>>a>>b;cout<<"该学生此门成绩为:"<<come[a-1]->grades[b-1];}运行结果:(注:文档可能无法思考全面,请浏览后下载,供参考。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

第六章实验题一.基础题1.#include <iostream>using namespace std;void main(){int a=20,b=40,c=60,temp;int &x=a,&y=b,&z=c;int *p1,*p2,*p3;p1=&a;p2=&b;p3=&c;temp=*p1;*p1=*p3;*p3=temp;cout<<endl;cout<<"一、用指向变量的指针形式输出改变量的地址:"<<endl;cout<<" "<<endl;cout<<" (1)变量a的地址为:"<<&a<<endl;cout<<" (2)变量b的地址为:"<<&b<<endl;cout<<" (3)变量c的地址为:"<<&c<<endl;cout<<endl<<endl;cout<<"二、用变量的别名输出该变量的值:"<<endl;cout<<" "<<endl;cout<<" (1)变量a的值为:"<<a<<" "<<"a的别名的值为:"<<x<<endl;cout<<" (1)变量a的值为:"<<a<<" "<<"b的别名的值为:"<<y<<endl;cout<<" (1)变量a的值为:"<<a<<" "<<"c的别名的值为:"<<z<<endl;system("pause");}2.#include <iostream>using namespace std;void comp(int a[]){int max = 0, min = 0;for (int i = 0; i < 10; i++){if (i == 0)min = a[i];if (i == 0)max = a[i];if (i > 0){if (a[i] > max)max = a[i];if (a[i] < min)min = a[i];}}cout << "最大值为:" << max << endl;cout << "最小值为:" << min << endl; }void main(){int a[10], *p;p = a;for (int i = 0; i<10; i++) cin >> a[i];comp(p);system("pause");}3.#include<iostream> using namespace std; void main(){int count=0;char *p = new char[];p = "This is a sapphire pen."; while (*p){if (*p == 's')count++;p++;}cout << count << endl; system("pause");}4.#include<iostream>using namespace std;void main(){int s=0;//初始化输出次数int a[3][4]={{1,2,3,4},{5,6,7,8},{9,10,11,12}};//数组的赋值int *p=&a[0][0];//数组的第一项赋值给指针cout<<&a[0][0]<<" "<<a<<" "<<a[0]<<endl;//三个都是输出一行一列数字的地址cout<<&a[1][0]<<" "<<a+1<<" "<<a[1]<<endl;//三个都是输出二行一列数字的地址cout<<&a[2][0]<<" "<<a+2<<" "<<a[2]<<endl;//三个都是输出三行一列数字的地址cout<<"---------------------------------"<<endl;for(int i=0;i<12;i++){cout<<&p[i]<<" ";s++;//依次输出数组的地址并统计次数if(s%4==0) cout<<endl;//每输出四个换行一次}cout<<"---------------------------------"<<endl; s=0;//再次初始化输出次数for(int i=0;i<12;i++){s++;cout<<p[i]<<" ";//输出数组中的数if(s%4==0)cout<<endl;//每输出四个换行一次}system("pause");}5.#include<iostream>using namespace std;void main(){int a[2][3]={11,22,33,44,55,66};int (*p)[3],*q,i;cout<<" 二维数组的内容:"<<endl;for(int i=0;i<=1;i++){for(int j=0;j<=2;j++)cout<<"a["<<i<<"]"<<"["<<j<<"]="<<a[i][j]<<" ";cout<<endl;}cout<<endl;cout<<" 二维数组的地址:"<<endl;for(i=0;i<=1;i++){for(int j=0;j<=2;j++)cout<<"&a["<<i<<"]"<<"["<<j<<"]="<<&a[i][j]<<" ";cout<<endl;}cout<<endl;cout<<" 二维数组的首地址:"<<endl;cout<<"&a[0][0]="<<&a[0][0]<<" "<<"a="<<a<<" "<<"&a="<<&a<<" "<<"a[0]="<<a[0]<<""<<"&a[0]="<<&a[0]<<endl;cout<<endl;p=a;cout<<" 二维数组的行地址:"<<endl;cout<<"p[0]="<<p[0]<<""<<"&p[0]="<<&p[0]<<endl;cout<<"a[0]="<<a[0]<<""<<"&a[0]="<<&a[0]<<endl;cout<<"p[1]="<<p[1]<<""<<"p[1]+1="<<p[1]+1<<endl;cout<<" 二维数组的行地址:"<<endl;cout<<"p="<<p<<" "<<"&p:"<<&p<<" "<<"p[0]="<<p[0]<<" "<<"p[1]="<<p[1]<<" "<<"p[2] = "<<p[2]<<endl;cout<<"a[0] = "<<a[0]<<" "<<"&a[0] = "<<&a[0]<<endl;cout<<"&p[0]:"<<&p[0]<<endl;cout<<"&p[0][0] : "<<&p[0][0]<<" "<<"&p[0][1] = "<<&p[0][1]<<" "<<"&p[1][0] = "<<&p[1][0]<<endl;cout<<"p[0][0] : "<<p[0][0]<<" "<<"p[1][0] = "<<p[1][0]<<endl; p=&a[0];cout<<"p : "<<p<<endl; cout<<"&p : "<<&p<<endl;cout<<"p[0] : "<<p[0]<<endl;cout<<"&p[0] : "<<&p[0]<<endl;cout<<"&p[0][0] : "<<&p[0][0]<<endl;cout<<"p[0][0] : "<<p[0][0]<<endl;q=a[0];cout<<"&q : "<<&q<<endl;cout<<"&q[0] : "<<&q[0]<<endl;cout<<"q[0] : "<<q[0]<<endl;system("pause");}二.编程题1.#include<iostream> using namespace std;void main(){inta[10]={6,12,34,56,78,89,90,409,800,2300},b[11],y,m,*p=b;cout<<"原本数组是:";for(int i=0;i<10;i++){cout<<a[i]<<" ";}cout<<endl;cout<<"请输入所要插入的数:";cin>>y;if (y <= a[0])m = 0;for (int j = 0; j < 9; j++){if ((y <= a[j + 1]) && (y >= a[j])){m = j + 1;}}for (int i = 0; i<m; i++){b[i] = a[i];}*(p + m) = y;for (int j = m + 1; j<11; j++) {b[j] = a[j - 1];}cout << "插入后数组:";for (int t = 0; t<11; t++){cout << *(p + t) << " ";}cout << endl;system("pause");}2.#include<iostream>#include<string>using namespace std;void main(){char*Names[5];char*TEMP;int i,j;for (i = 0; i < 5; i++){Names[i] = new char[50];cout << "输入任意五个国家名:" << endl;/*gets_s(Names[i], 50);*/cin >> Names[i];}for (j = 0; j < 4; j++){for (i = 0; i < 4-j; i++){if (strcmp(Names[i], Names[i+1]) > 0){TEMP= new char[50];strcpy_s(TEMP, 50, Names[i + 1]);strcpy_s(Names[i+1], 50, Names[i]);strcpy_s(Names[i], 50, TEMP);delete TEMP;}}}cout << "排序后:" << endl;for (i = 0; i<5; i++)cout << Names[i] << endl;system("pause");}#include<iostream>using namespace std;struct student{long num;float score[5];};student stu[3]={201201,80,91,72,89,60,201202,66,75,90,85,90,201203,75,70,89,78,68};void main(){student* p = stu;int m, n;cout << "课程号:数学分析(1),大学物理(2),大学英语(3),电路分析(4),马原(5)" << endl;cout << "请输入学生学号和课程号:";cin >> m >> n;if (m == 201201)if (n == 1){cout << p->score[0];}if (n == 2){cout << p->score[1];}if (n == 3){cout << p->score[2];}if (n == 4){cout << p->score[3];}if (n == 5){cout << p->score[4];}}if (m == 201202){if (n == 1){cout << (p + 1)->score[0];} if (n == 2){cout << (p + 1)->score[1];} if (n == 3){cout << (p + 1)->score[2];}if (n == 4){ cout << (p + 1)->score[3];}if (n == 5){cout << (p + 1)->score[4];}}if (m == 201203){if (n == 1){cout << (p + 2)->score[0];}if (n == 2){cout << (p + 2)->score[1];}if (n == 3){cout << (p + 2)->score[2];}if (n == 4){cout << (p + 2)->score[3];}if (n == 5){cout << (p + 2)->score[4];}}cout << endl;system("pause"); }。

相关文档
最新文档