云南大学软件学院实验报告
云南大学软件学院Java实验五
云南大学软件学院实验报告:定欢学号:20141120188 班级:日期:2016年10月20日成绩:JAVA实验五一、实验目的:Applying OO Concepts Using Java二、实验要求:Create a class called Circle.java with fields named radius〔半径〕, area〔面积〕, and diameter〔直径〕. Include methods named setRadius(),getRadius(), and computeDiameter(), which calculates the circle's diameter, and computeArea(), which computes the circle's area.Hint: diameter of a circle is twice its radius.Hint: area of a circle is 3.14 multiplied by the square of the radius.Create a class called TestCircle. java whose main method declares2 Circle objects. Using setRadius() method, assign one Circle a smallradius value and assign another a larger radius value. CallcomputeDiameter() and computeArea for each circle and display the results.Output result of using command input "5 8":The area of a is 78.5The diameter of a is 10.0The area of b is 200.96The diameter of b is 16.0三、实验内容:1、Circle.java2、CircleTest.java3、结果附加题:1.Monkey.java1.import java.util.Random;2.import java.util.Scanner;3.4.class Monkey {5.private String name;6.private double weight;7.private int age;8.private static String hab = "吃香蕉";9.public void setName(String name){ = name;11.}12.13.public void setWeight(double weight){14.this.weight = weight;15.}16.17.public void setAge(int age){18.this.age = age;19.}20.21.public String getName(){22.return name;23.}24.25.public double getWeight(){26.return weight;27.}28.29.public int getAge(){30.return age;31.}32.//默认构造方法33.public Monkey(){34.35.}36.37.//带参数构造方法38.public Monkey(String name, double weight, int age){ = name;40.this.weight = weight;41.this.age = age;42.}43.44.public void climbTree(){45.Random r = new Random();46.int high = r.nextInt(60)+40;47.int banana = r.nextInt(54);48.System.out.println(name +"会爬树"+"能爬"+high);49.50.if(high>=60){51.System.out.println(name+"会爬树,"+"能爬"+high+","+"摘到"+banana+"香蕉");52.System.out.println("剩下"+(BananaTree.BanaSum-banana)+"香蕉");53.}54.55.else56.System.out.println("不能摘到香蕉");57.58.}59.60. }2.BananaTree:public class BananaTree {double treeHigh;static double BanaSum;public void settreeHigh(double treeHigh){this.treeHigh = treeHigh;}public void setBanaSum(double BanaSum){this.BanaSum = BanaSum;}public double treeHigh(){return treeHigh;}public double getBanaSum(){return BanaSum;}public BananaTree(){}public BananaTree(double treeHigh,double BanaSum){this.treeHigh = treeHigh;this.BanaSum = BanaSum;}}3.MonkeyTest.javapublic class MonkeyTest {public static void main(String[] args) {// TODO Auto-generated method stubMonkey monkey1 = new Monkey();monkey1.setName("甲");monkey1.setAge(3);monkey1.setWeight(40);Monkey monkey2 = new Monkey("乙", 43, 3);BananaTree bt = new BananaTree();bt.settreeHigh(86);bt.setBanaSum(54);monkey1.climbTree();monkey2.climbTree();}}4.结果:四、实验总结:通过此次实验,进一步熟悉了类的构造方法,包括带参数的构造方法和默认构造方法。
云南大学--软件学院--数据库实验4
云南大学软件学院实验报告课程:数据库原理与实用技术实验学期: 2012-2013学年第二学期任课教师:专业:学号:姓名:成绩:实验4 数据查询一、实验目的理解T-SQL语言的使用;熟练掌握数据查询语句;掌握合计函数的使用。
二、实验内容1、CAP数据库的查询(记录每个查询的SQL语句和查询结果)(1)建立CAP数据库,输入C、A、P、O四张表;图表 1 创建cap数据库图表 2创建四个表图表 3向表中插入数据图表 4表的内容(2)完成课后习题[3.2]b、[3.5]、[3.8]a,b、[3.11]b,f,j,l[3.2] (b)Retrieve aid values of agents who receive the maximum percent commission.图表 5最高佣金百分率[3.5] Consider the problem to find all (cid, aid) pairs where the customer does not place an order through the agent. This can be accomplished with the Select statementselect cid, aidfrom customers c. agents awhere not exists(select * from orders x where x.cid = c.cid and x.aid =a.aid) ;Is it possible to achieve this result using the NOT IN predicate in place of the NOT EXISTS predicate with a single Subquery? With more than one Subquery? Explain your answer and demonstrate any equivalent form by execution.图表 6 3.5 not in[3.8](a) Write a Select statement with no WHERE clause to retrieve all customer cids and the maximum money each spends on any product. Label the columns of the resulting table: eid, MAXSPENT.图表 7 3.8(b) Write a query to retrieve the AVERAGE value (over all customers) of the MAXSPENT of query (a)图表 8 3.8(b)[3.11] (b) We say that a customer x orders a product y in an average quantity A if A is avg(qty) for all orders rows with cid = x and pid = y. Is it possible in a single SQL statement to retrieve cid values of customers who order all the products that they receive in average quantities (by product) of at least 300?图表 9 3.11 (b)(f) Get pid values of products that are ordered by all customers in Dallas.图表 10 3.11 (f)(j) Use a single Update statement to raise the prices of all products warehoused in Duluth or Dallas by 10%. Then restore the original values byrerunning the procedure that you originally used to create and load the products table.图表 11 3.11 (j)(l) Write an SQL query to get aid and percent values of agents who take orders from all customers who live in Duluth. The aid values should be reported in order by decreasing percent. (Note that if percent is not retrieved in the select list, we cannot order by these values.)图表 12 3.11 (i)2、Employee数据库的查询(记录每个查询的SQL语句和查询结果)(1)向表中插入数据。
云南大学软件学院数据结构实验1
实验难度: A □ B □ C □学期:2017秋季学期任课教师: 刘宇实验题目:组员及组长:承担工作:联系电话:电子邮件:完成提交时间:2017年10月24日一、【实验构思(Conceive)】(10%)(本部分应包括:描述实验实现的基本思路,包括所用到的离散数学、工程数学、程序设计等相关知识,对问题进行概要性地分析)实验要求制作一个复数计算器,要求能进行实数和虚数的混合运算,首先要解决的问题是复数的四则运算,确保运算正确无误。
然后要解决的就是分离复数这个问题。
分离复数最简单的方法就是输入复数的时候分别输入实部虚部,然后打印。
但这过于简单,于是采取输入一个字符串来接入这个复数,然后用数组的方法进行实部虚部的分离。
用到的数学知识:复数四则运算,与或非运算,进行分支判断;程序设计知识:目标分析->设计算法->程序编写->后期调试。
二、【实验设计(Design)】(20%)(本部分应包括:抽象数据类型的定义和基本操作说明,程序包含的模块以及各模块间的调用关系,关键算法伪码描述及程序流程图等,如有界面则需包括界面设计,功能说明等)抽象数据类型的定义:typedef struct Complex //构造复数结构Complex{float real; //定义实部为realfloat imag; //定义虚部为imag}Complex;基本操作:功能一可以字符串形式输入一个复数,用数组的方法从字符串中分离出实部和虚部;功能二可以对输入的两个复数进行简单的加减乘除的四则运算。
模块:加法函数:Complex Add(Complex z1, Complex z2)减法函数:Complex Sub(Complex z1, Complex z2)乘法函数:Complex Mul(Complex z1, Complex z2)除法函数:Complex Div(Complex z1, Complex z2)打印函数:void print_Complex(Complex z)分离实部函数:float Getreal(Complex z)分离虚部函数:float Getimag(Complex z)分离函数:void spread_Complex()算法伪码描述(分离函数):输入一个复数字符串;实部标志为flag1,虚部标志为flag2,得到flag1和flag2的取值,判断该复数是否是完整的复数,或是纯实数、纯虚数;用符号来判断一个完整的复数的实部虚部,如果判断出字符串中接收到了‘+’或者‘-’,则符号前面的算实部,将符号舍去,后面的即为虚部,直到遇上‘i’。
云南大学软件学院数据结构实验二实验报告——多项式计算器
云南大学软件学院数据结构实验报告2010秋季学期(本实验项目方案受“教育部人才培养模式创新实验区(X3108005)”项目资助)学号:姓名:专业:指导老师:实验难度A□B□ C □承担任务(难度为C时填写)指导教师评分(签名)【实验题目】实验2. 线性表及其应用【问题描述】用C或C++语言设计并实现一个一元稀疏多项式的简单计算器。
【基本要求】一元稀疏多项式简单计算器的基本功能是:1、输入并建立多项式2、输出多项式,序列按指数降序排列3、多项式A(x)和B(x)相加,并建立多项式A(x)+B(x)4、多项式A(x)和B(x)相减,并建立多项式A(x)-B(x)5、给定 x 的值,计算多项式6、多项式A(x)和B(x)相乘,建立多项式A(x)*B(x) (* 选做,作为难度B的操作)【CDIO项目要求】1、有完整的CDIO四个阶段描述2、有友好美观的操作界面3、有软件使用说明或帮助文档4、项目成员分工明确,团结协作【实现提示】一、【实验构思(Conceive)】(10%)本实验通过C语言实现了多项式加法、减法、乘法、多项式求导、多项式积分的功能。
利用了冒泡排序的算法作为排序的核心算法。
运用了高等数学中多项式的求导积分的知识。
二、【实验设计(Design)】(15%)本程序定义了抽象数据结构listnode,用于存储多项式的系数和指数并存储指向下一个listnode的指针来构成链表。
本程序包含如下*个函数:Main函数:调用input函数—>调用bubble_sort函数—>调用operplus函数—>调用oper_minus函数—>调用oper_mul函数—>调用oper_dy函数—>调用oper_jifen 函数。
Oper_plus函数:将两个链表的相应项系数相加,指数不同项不操作,存入新链表,再调用排序算法,使之为降序排列。
Oper_minus函数:将两个链表的相应项系数相减,指数不同项不操作,存入新链表,再调用排序算法,使之为降序排列。
云大JAVA实验10Lab #10(陆歌浩)
云南大学软件学院实验报告课程:Java程序设计实验学期:2012-2013学年第一学期任课教师:陆歌浩专业:软件工程学号:序号:姓名:成绩:实验10 事件处理一、实验目的练习Java中事件处理的应用。
二、实验内容Program 1Create an application ChangeBallColor that displays a panel. This panel will contain two buttons (one for red and one for blue). It will also display a filled in circle. When the user clicks on a button, the circle should change to that color. So, if a user clicks the blue button, the circle will change to blue. Similarly, if a user clicks the red button, the circle will turn to red.实验代码:package b10;import java.awt.*;import javax.swing.*;import java.awt.event.*;import java.awt.geom.*;public class ChangeBallColor {public static void main(String[] args) {EventQueue.invokeLater(new Runnable(){public void run(){ChangeColorFrame frame = new ChangeColorFrame();frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setVisible(true);}});}}class ChangeColorFrame extends JFrame{public ChangeColorFrame(){setTitle("孙金文-20101120007");setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);setLocation(450,250);drawball = new DrawBall();drawball.setColor(Color.BLUE);JPanel northPanel = new JPanel();blueButton = new JButton();redButton = new JButton();blueButton.setText("变蓝");blueButton.setForeground(Color.YELLOW);blueButton.setBackground(Color.BLUE);redButton.setText("变红");redButton.setForeground(Color.YELLOW);redButton.setBackground(Color.RED);northPanel.add(blueButton);northPanel.add(redButton);add(northPanel,BorderLayout.NORTH);add(drawball);blueButton.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent evt) {drawball.setColor(Color.BLUE);drawball.repaint();}});redButton.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent evt) {drawball.setColor(Color.RED);drawball.repaint();}});}private DrawBall drawball;private JButton blueButton;private JButton redButton;private static final int DEFAULT_WIDTH = 400;private static final int DEFAULT_HEIGHT = 300;}class DrawBall extends JPanel{Color color = null;public void setColor(Color c){this.color = c;}public void paintComponent(Graphics g){Graphics2D g2 = (Graphics2D)g;super.paintComponent(g);Ellipse2D circle = new Ellipse2D.Double();circle.setFrameFromCenter(BALL_X, BALL_Y,BALL_X+RADIUS,BALL_Y+RADIUS);g2.setPaint(color);g2.fill(circle);g2.draw(circle);}public static final int BALL_X=190,BALL_Y = 100,RADIUS = 80;}运行截图:。
云南大学软件学院报告
课程:数据结构实验学期:2014-2015学年第一学期任课教师:专业:信息安全学号:姓名:成绩:实验5 图基础实验一、实验目的1.掌握图的存储结构及其遍历。
二、实验软硬件环境(CPU、OS、IDE):三、实验任务(要求写出核心代码,并对运行结果截图)1)使用邻接矩阵和邻接表储表示分别实现如下给定的图1、图2、图3所示图的物理存储结构。
2)在1)所建立的图形存储结构上分别实现深度优先搜索遍历和广度优先搜索遍历,并给出遍历结果(序列)。
图3 有向图实验代码:#include<stdio.h>#include<stdlib.h>#define MAXVEX 20#define OK 1#define ERROR 0#define OVERFLOW -1#define INFINITY 65535#define QueueSize 20 //队列中最大元素个数typedef int QElemType; //队列的元素的类型typedef int VertexType;typedef int EdgeType;typedef enum{False,True}Boolean; //Boolean是布尔类型,其值是ture或false Boolean visited[MAXVEX]; //访问标志的数组。
typedef struct{VertexType vexs[MAXVEX];EdgeType arc[MAXVEX][MAXVEX];int numVertexes,numEdges;} MGraph; //邻接矩阵。
typedef struct EdgeNode //边表结点。
{int adjvex;struct EdgeNode *next;}EdgeNode;typedef struct VertexNode //顶点表结点。
{int data;EdgeNode *firstedge;}VertexNode,AdjList[MAXVEX];typedef struct{AdjList adjlist;int numVertexes,numEdges; //图中当前顶点数边数。
云南大学软件学院数据结构实验六实验报告——赫夫曼编码译码器
云南大学软件学院数据结构实验报告(本实验项目方案受“教育部人才培养模式创新实验区(X3108005)”项目资助)实验难度: A □ B □ C □学期:任课教师:实验题目: 实验五树及其应用小组长:联系电话:电子邮件:完成提交时间:年月日云南大学软件学院2010学年秋季学期《数据结构实验》成绩考核表学号:姓名:本人承担角色:课题分析,算法设计,程序编写,后期调试,完成实验报告综合得分:(满分100分)指导教师:年月日(注:此表在难度为C时使用,每个成员一份。
)云南大学软件学院2010学年秋季学期《数据结构实验》成绩考核表学号:姓名:本人承担角色:课题分析,算法设计,后期调试,完成实验报告综合得分:(满分100分)指导教师:年月日(注:此表在难度为C时使用,每个成员一份。
)(下面的内容由学生填写,格式统一为,字体: 楷体, 行距: 固定行距18,字号: 小四,个人报告按下面每一项的百分比打分。
难度A满分70分,难度B满分90分)一、【实验构思(Conceive)】(10%)(本部分应包括:描述实验实现的基本思路,包括所用到的离散数学、工程数学、程序设计、算法等相关知识)1.数据结构算法的知识:●树的定义。
●树的节点和边的表示。
●树的存储结构。
●树的分类:二叉树—》Heffman树。
●树的遍历:前序遍历,中序遍历,后序遍历。
2.面向对象的程序设计相关知识:●C#基本语法知识。
●类的定义,实例化。
●对象的生成调用。
●变量的传递。
二、【实验设计(Design)】(20%)(本部分应包括:抽象数据类型的功能规格说明、主程序模块、各子程序模块的伪码说明,主程序模块与各子程序模块间的调用关系)本实验创建了四个类Form类//用于窗口的初始化,控制各控件的属性和动作Data类//用于本程序所需的频度表数组的生成以及调用HuffmanTree类//用于构造Huffman树以及控制树的各项操作HuffmanTreeNode类//用于构造Huffman树的节点抽象数据类型的功能规格说明:窗口初始化:private void Form1_Load(object sender, EventArgs e)转换模式:private void button1_Click(object sender, EventArgs e)private void button1_Click(object sender, EventArgs e)开始按钮:private void button3_Click(object sender, EventArgs e)声明全局数组:public member[] allMembers = new member[27];定义结构体数组:public struct member{public char ch;//保存频度字符public int frequentness;//保存频度}Data的构造函数(创建Huffman树)public Data()Data类中的寻找当前最大项函数:public int FindMax()Data类中的寻找当前第二大项函数:public int FindSecondMax()Data类中的计算当前有效项的数目的函数:public int Count() HuffmanTreeNode类中创建节点的构造函数:public HuffmanTreeNode (char ch2 ,int frequentness2)HuffmanTree类中定义的节点类型:public HuffmanTreeNode root,p,r; HuffmanTree类中实例化一个Data类来构造频度表:public DatafrequentnessTable; HuffmanTree类中的构造函数,创建一棵Huffman树:public HuffmanTree() HuffmanTree类中的成员函数,对于指定的字符实行中序遍历,遍历完之后逆向回溯得到该字符的Huffman编码:public int SearchTree()HuffmanTree类中的两个节点变量,用于判断左右子树:public int SearchTree()主程序模块伪代码说明:创建新的字母频度表:frequentnessTable = new Data();创建栈来倒装输出赫夫曼编码:Stack<char> HuffmanCode = Stack<char>;退出程序:this.Close()子程序伪代码说明(HuffmanTree):构建Huffman树:public HuffmanTreeNode root,p,r;核心程序段(生成Huffman编码):while (r == root){r = p.parent;if (p == r.left)HuffmanCode.Push('1');//栈中存1elseHuffmanCode.Push('0');//栈中存0p = p.parent;}返回栈中元素个数:public int count { get{ return list.Count; } }主程序模块与各子程序模块间的调用关系:Class Form1调用Class Data初始化程序所要的各项数据。
实验报告模板—汇编语言
指导教师 (签名):一.实验原理(基本知识简单介绍、算法、流程)二.实验结果(截图,提供实验测试/调试的结果等,在空白地方手写注释)Student strucm_sName db 6 dup(' ')m_sNum db 8 dup(' ')m_sScore db 3 dup(' ')Student endsstsg segment stack 's'dw 32 dup(?)stsg endsanykey macromov ah,7int 21hendmanykeyback macroanykeyshowmsg backendmcrlfm macropush axpush dxmov ah,9lea dx,crlfint 21hpop dxpop axendmexchange macro i,jpush cxpush sipush dimov cx,17;t=[i],即t=前项mov si,ilea di,stutemprep movsbmov cx,17;i=j,si->后项,即前项=后项mov di,i ;rep movsbmov cx,17;j=t,di->后项,即后项=tlea si,stutemprep movsbmov swapped,1pop dipop sipop cxendmspace macropush dxpush axlea dx,gapmov ah,9int 21hpop axpop dxendmshowmsg macro npush axpush dxmov ah,9lea dx,msg&nint 21hpop dxpop axendmmovitem macro dst,srcpush cxpush dipush sicldmov cx,17lea di,[dst]lea si,[src]rep movsbpop sipop dipop cxendmdata segmentstudentx student 30 dup(<>)stutemp db 17 dup (0),'$'studisp db 19 dup(0),'$'namepar LABEL BYTEmaxnlen db 7namelen db ?namefld db 7 dup(?)numpar label bytemaxmlen db 9numlen db ?numfld db 9 dup(?)scopar label bytemaxsco db 4scolen db ?scofld db 4 dup(?);输入文件路径缓冲区pathpar label bytepathmax db 40pathlen db ?pathnam db 40 dup(?)ae90 db 0ae80 db 0ae70 db 0ae60 db 0b60 db 0msg_b60 db 9,9,'Scores<60:$'msg_ae60 db 9,9,'Scores>=60:$'msg_ae70 db 9,9,'Scores>=70:$'msg_ae80 db 9,9,'Scores>=80:$'msg_ae90 db 9,9,'Scores>=90:$'cur_i dw ?crlf db 13,10,'$'titl db ' Students Management System',0DH,0AH,' ',0DH,0AH,0DH,0AHmenu1 db ' I(Insert the data of the students)',0dh,0ah ;menumenu2 db ' L(Browse the data of the students)',0dh, 0ahmenu3 db ' Q(Query the data of the students)',0dh, 0ahmenu4 db ' D(Delete the data of the students)',0dh, 0ahmenu5 db ' M(Modify the data of the students)',0dh,0ahmenu7 db ' P(Print the data of the students)',0dh, 0ahmenu8 db ' C(Statistics the data of the students)',0dh, 0ahmenu9 db ' E(Exit the System)',0dh, 0ah,'$'msgmenu5_1 db 0DH,0AH,'1-----Modify name',0DH,0AHmsgmenu5_2 db '2-----Modify number',0DH,0AHmsgmenu5_3 db '3-----Modify score',0DH,0AH,'$'msgmenu3_1 db 0DH,0AH,'1-----Search name',0DH,0AHmsgmenu3_2 db '2-----Search number',0DH,0AHmsgmenu3_3 db '3-----Search score',0DH,0AH,'$'mmenutip db ' choose a number from the menu above',0DH,0AH,'$'msgprinttitle db 0DH,0AH,0DH,0AH,' sno sname score ',0DH,0AH,'$'gap db ' $'stu dw ?stustored dw 0swapped db 0sav_cnt dw ?stusaved dw 0saveflag db 1errcde db 0endcde db 0endaddr dw ?filehandle dw ?msg_titleln db ' ------------------------------------',13,10,'$'msgsepln db '--------------------------------',0DH,0AH,'$'msg02 db 'Please input the new student info.',13,10,'$'msg03 db 'Name:','$'msg04 db 'ID:','$'msg05 db 'Score:','$'msg07 db 'Successly Saved!',13,10,'$'msgdeled db 'Successly Deleted a item!',13,10,'$'msgmoded db 'Successly Modified a item content!',13,10,'$'msginsed db 'Successly Inserted item(s)!',13,10,'$'msgqforins db 'Insert this item?(y/n):',13,10,'$'msgback db 'Press any key to back.$'msgexit db 'Press any key to exit.$'msg09 db 'students out of 30.',13,10,'$'msg20 db 'There are more than 30 students.',13,10,'$'msg21 db 'Save as:',13,10,'$'msg22 db 'Please input the file you want to operate:',13,10,'$'msg23 db 'Read successly!',13,10,'$'msg27 db 'There isn',27h,'t any student.',13,10,'$'msgnoext db 'There is no such item!',13,10,'$'msgnaminfid db 'Please input a name to find:',13,10,'$'msgnuminfid db 'Please input a number to find:',13,10,'$'msgscoinfid db 'Please input a score to find:',13,10,'$'msgstattit db 9,9,'The result of statistics is listed as follow:',13,10,'$'msg_nname db 'Please input a new one:',13,10,'$'msg_nnum db 'Please input a new num.:','$'msg_nsco db 'Please input a new score.:','$'msgqsave db 'The ducoment have not saved.Do you want to save it now(y/n)?','$'msg_delnamin db 'Please input the name you want to delete:',13,10,'$'msg_modname db 'Please input the name field you want to modify:',13,10,'$' msg_modnum db 'Please input the number field you want to modify:',13,10,'$'msg_modsco db 'Please input the score field you want to modify:',13,10,'$' opnmsg db '***Error occured while opening file***',13,10,'$' wrtmsg db '***Error occured while writing file***',13,10,'$' readmsg db '***Error occured while reading file***',13,10,'$' routemsg db '***Path name is invalid***',13,10,'$'data endscode segmentassume cs:code,ds:data,ss:stsg,es:datamain proc farstart:mov ax,datamov ds,axmov es,axmainmenu:mov AX,0600Hmov CX,0000Hmov DX,174FHmov BH,07int 10Hmov AH,02 ;set cursormov BH,0mov DX,0100Hint 10Hlea DX,titl ;display menumov AH,9int 21Hshowmsg _titlelnlea DX,mmenutipmov AH,9int 21Hcase:mov ah,0int 16hcmp ah,17h;'i'je addonecmp ah,26h;'l'je browsecmp ah,19h;'p'je displaycmp ah,10h;'q'je querycmp ah,20h;'d'je del_intermcmp ah,2eh;'c'je statiscmp ah,32h;'m'je changecmp ah,12h;'e'je exitdisplay:call display_inanykeybackjmp mainmenuquery:call query_inanykeybackjmp mainmenubrowse:call browse_inanykeybackjmp mainmenuaddone:call insert_inanykeybackjmp mainmenuexit:call quitstatis:call stat_inanykeybackjmp mainmenudel_interm:jmp deletechange:call mod_inanykeybackjmp mainmenudelete:call del_inanykeybackjmp mainmenubeep:mov AH,14mov AL,7mov BH,0int 10Hjmp mainmenumain endp;------------------------------------------------------------------------ browse_in proc nearcall near ptr clearcall near ptr cursorcall near ptr readallcall name_sortcall near ptr printretbrowse_in endp;------------------------------------------------------------------------ del_in proc nearcall clearcall cursorcall delete_inretdel_in endp;------------------------------------------------------------------------ query_in proc nearcall clearcall cursorcall bg_searchretquery_in endp;------------------------------------------------------------------------ stat_in proc nearcall clearcall cursorcall near ptr statretstat_in endp;------------------------------------------------------------------------ insert_in proc nearcall clearcall cursorcall near ptr inputcall name_sortretinsert_in endp;------------------------------------------------------------------------ display_in proc nearcall clearcall cursorcall near ptr printretdisplay_in endp;------------------------------------------------------------------------ mod_in proc nearcall clearcall cursorcall printcall bg_modifycall name_sortretmod_in endp;------------------------------------------------------------------------ delete_in proc nearpush axpush dxcall printcrlfmmov ah,9lea dx,msg_delnaminint 21hcall near ptr inputnamecall near ptr delshowmsg deledqdel:pop dxpop axretdelete_in endp;------------------------------------------------------------------------ bg_search proc nearshowmsg menu3_1mov ah,1int 21h;getch()crlfmcmp al,'1'je q1cmp al,'2'je q2showmsg scoinfidlea bx,studentx+14mov dx,3jmp bgsearq1:showmsg naminfidcall near ptr inputnamelea bx,studentxmov dx,1jmp bgsearq2:showmsg numinfidcall near ptr inputnumlea bx,studentx+6mov dx,2bgsear:push bxpush dxcall near ptr search;search(studentx,1)cmp ax,-1je qinsshowmsg printtitleshowmsg seplnpush simov si,axcall near ptr printlinepop sijmp qqueqins:showmsg qforinsmov ah,01int 21hcrlfmcall inputnumcall inputscocall storshowmsg insedmov saveflag,0qque:retbg_search endp;------------------------------------------------------------------------ bg_modify proc nearpush axpush bxpush dxshowmsg menu5_1;display modify submenumov ah,1int 21h;getch()crlfmcmp al,'1'je t1cmp al,'2'je t2mov bx,3call inputscojmp cint1:call inputnamemov bx,1jmp cint2:mov bx,2call inputnumcin:push bxcall near ptr modifycmp ax,-1je qmodicrlfmshowmsg modedqmodi:pop dxpop bxpop axretbg_modify endp;------------------------------------------------------------------------ quit proc nearcmp saveflag,0je qforsavjmp qsysqforsav:call clearcall cursorshowmsg qsavemov ah,1int 21hcmp al,'y'je savitjmp qsyssavit:call savemov ah,3eh;close filemov bx,filehandleint 21hqsys:mov ax,4c00hint 21hretquit endp;------------------------------------------------------------------------ search proc nearpush bpmov bp,sppush dipush bxpush sipush cxpush dxmov di,[bp+6]mov dx,stustoredmov bx,[bp+4];bx:typemov bp,dicmp bx,1je snamcmp bx,2je snummov cx,3mov bx,cxlea ax,scofldjmp loop1snam:mov cx,6mov bx,cxlea ax,namefldjmp loop1snum:mov cx,8mov bx,cxlea ax,numfldloop1:mov si,axrepe cmpsbje foundadd bp,17mov di,bpdec dhjnz loop1mov ax,-1showmsg noextjmp qsearchfound:mov ax,bpmov dx,stustoredsub dx,bxmov cur_i,dxqsearch:pop dxpop cxpop sipop bxpop dipop bpret 4search endp;------------------------------------------------------------------------ name_sort proc nearpush sipush dipush axpush bxpush dxpush cxcmp stustored,1je qsortlea bx,studentxpush bxmov ax,stustoredsub ax,1mov bl,17mul blpop bxadd bx,axmov dx,stustoredsub dx,1 ;dx:il1:mov swapped,0sub bx,17mov endaddr,bxpush bxlea si,studentx;si:j,j=0l2:mov di,siadd di,17mov bx,dimov ax,sirepe cmpsbjbe s3exchange ax,bxs3:mov si,axadd si,17;j++cmp si,endaddrjbe l2pop bxcmp swapped,0je qsortdec dxjnz l1qsort:pop cxpop dxpop bxpop axpop dipop siretname_sort endp;------------------------------------------------------------------------ del proc nearpush bxpush dipush sipush cxlea bx,studentxpush bxmov bx,1;search(studentx,name)push bxcall near ptr searchcmp ax,-1je nomatchmov di,axmov si,diadd si,17;si:j,di:imov cx,stustoredsub cx,cur_imovit:movitem di,simov di,si;si:j+1 ,di:jmov dx,diadd dx,17mov si,dxloop movitmov ax,1mov saveflag,0sub stustored,1nomatch:pop cxpop sipop dipop bxretdel endp;------------------------------------------------------------------------ insert proc nearpush sipush dipush axpush bxpush cxcmp stustored,0je exilea si,stutemplea di,studentxmov ax,stustoredmov bl,17mul bladd di,axmov cx,17;rep movsbinc stustoredexi:pop cxpop bxpop axpop dipop siretinsert endp;------------------------------------------------------------------------ stor proc nearpush axpush bxpush dxpush dipush sipush cxcmp namelen,0je qstocldmov ax,stustoredmov bl,17mul bllea dx,studentxmov stu,dxadd stu,axmov di,stulea si,namefldmov cx,6rep movsblea si,numfldmov cx,8rep movsbmov cx,3lea si,scofldrep movsbinc stustoredqsto:pop cxpop sipop dipop dxpop bxpop axretstor endp;------------------------------------------------------------------------ modify proc nearpush bpmov bp,sppush bxpush dxpush dipush cxmov bx,[bp+4]cmp bx,1je mdnamcmp bx,2je mdnumlea dx,studentx+14jmp findmdnam:lea dx,studentxjmp findmdnum:lea dx,studentx+6find:push dxpush bxcall near ptr searchcmp ax,-1je qu_modmov di,ax;cmp bx,1je mnamcmp bx,2je mnumlea dx,msg_nscomov ah,9int 21hlea dx,scoparmov ah,0ahint 21hmov cx,3lea si,scofldjmp mfymnam:lea dx,msg_nnamemov ah,9int 21hcall inputnamemov cx,6lea si,namefldjmp mfymnum:lea dx,msg_nnummov ah,9int 21hlea dx,numparmov ah,0ahint 21hmov cx,8lea si,numfldmfy:rep movsbmov saveflag,0mov ax,1qu_mod:pop cxpop dipop dxpop bxpop bpret 2modify endp;------------------------------------------------------------------------ stat proc nearpush cxpush bxpush dxpush axmov cx,stustoredlea bx,[studentx+14]sta:mov dx,[bx]mov ah,[bx+2]cmp dl,'1'je a90cmp dh,'9'jae a90cmp dh,'8'jae a80cmp dh,'7'jae a70cmp dh,'6'jae a60add b60,1jmp repeata90:add ae90,1jmp repeata80:add ae80,1jmp repeata70:add ae70,1jmp repeata60:add ae60,1repeat:add bx,17loop stashowmsg stattitshowmsg _titlelnshowmsg _b60mov bl,byte ptr b60call deciasccrlfmshowmsg _titlelnshowmsg _ae60mov bl,byte ptr ae60call deciasccrlfmshowmsg _titlelnshowmsg _ae70mov bl,byte ptr ae70call deciasccrlfmshowmsg _titlelnshowmsg _ae80mov bl,byte ptr ae80call deciasccrlfmshowmsg _titlelnshowmsg _ae90mov bl,byte ptr ae90call deciasccrlfmshowmsg _titlelnmov ae90,0mov ae80,0mov ae70,0mov ae60,0mov b60,0pop axpop dxpop bxpop cxretstat endp;------------------------------------------------------------------- errm proc nearpush axmov ah,9int 21hmov errcde,01pop axreterrm endp;------------------------------------------------------------------- input proc nearpush axpush dxcall near ptr clearcall near ptr cursorcmp stustored,29ja i1mov ah,09lea dx,msg02;display promptint 21hiloop:cmp stustored,29ja i1call near ptr inputnamecmp namelen,0je i2call near ptr inputnumcall near ptr inputscocall near ptr storjmp iloopmov saveflag,0jmp i2i1:mov ah,9lea dx,msg20;'There are more than 30 students.' int 21hi2:showmsg back;'Press any key to back.'i3:mov saveflag,0pop dxpop axretinput endp;---------------------------------------------------------------------- inputname proc nearpush axpush dxpush bxpush cxshowmsg 03mov ah,0ahlea dx,nameparint 21hcrlfmmov bh,0mov bl,namelenmov cx,7sub cx,bxn10:mov namefld[bx],20hinc bxloop n10pop cxpop bxpop dxpop axretinputname endp;----------------------------------------------------------------------- inputnum proc nearpush axpush dxpush bxpush cxshowmsg 04mov ah,0ahlea dx,numparint 21hcrlfmmov bh,0mov bl,numlenmov cx,9sub cx,bxn20:mov numfld[bx]inc bxloop n20pop cxpop bxpop dxpop axretinputnum endp;---------------------------------------------------------------------- inputsco proc nearpush axpush dxpush bxpush cxshowmsg 05mov ah,0ahlea dx,scoparint 21hcrlfmmov bh,0mov bl,scolenmov cx,4sub cx,bxn21:mov scofld[bx],20hinc bxloop n21pop cxpop bxpop dxpop axretinputsco endp;------------------------------------------------------------------------ print proc nearpush sipush cxpush dxpush axcmp stustored,0je qprintcrlfmcrlfmshowmsg printtitleshowmsg seplnlea si,studentxmov cx,stustoredpline: call near ptr printlineloop plinepop axpop dxpop cxpop siqprint:retprint endp;------------------------------------------------------------------------ printline proc nearpush dipush cxpush dxpush axlea di,studisp;stutemp=studentx[i]mov cx,6rep movsbmov [studisp+6],9add di,1mov cx,8rep movsbmov [studisp+15],9add di,1mov cx,3rep movsbmov ah,9lea dx,studispint 21hcrlfmshowmsg seplnpop axpop dxpop cxpop diretprintline endp;------------------------------------------------------------------------ deciasc proc nearmov ch,100dmov cl,10dre:cmp ch,0je qdecimov al,bl;cbwdiv ch;mov bl,ahcall near ptr printitmov al,chcbwdiv clmov ch,aljmp reqdeci:retdeciasc endp;--------------------------------------------------------------------printit proc nearadd al,30hmov dl,almov ah,2int 21hretprintit endp;-------------------------------------------------------------------- stor2 proc nearpush sipush dipush axpush bxpush cxcmp stutemp,0je exittlea si,stutemplea di,studentxmov ax,stustoredmov bl,17mul bladd di,axmov cx,17;rep movsbinc stustoredpop cxpop bxpop axpop dipop siexitt: retstor2 endp;------------------------------------------------------------------------ get_path proc nearpush axpush bxpush dxshowmsg 22;'Please input the file you want to operate:' mov ah,0ahlea dx,pathparint 21h;crlfmmov bl,pathlenmov bh,0mov pathnam[bx],0pop dxpop bxpop axretget_path endp;--------------------------------------------------------------------openh proc nearpush axpush cxpush dxcall near ptr get_pathmov ah,3dhmov cx,0lea dx,pathnamint 21hjc o1mov filehandle,axpop dxpop cxpop axreto1:mov endcde,01lea dx,opnmsgcall near ptr errmpop dxpop cxpop axretopenh endp;-------------------------------------------------------------------- readall proc nearpush axmov endcde,0call near ptr openhcmp endcde,0jne rexit;endcde=1mov stustored,0contin:call near ptr readhcmp endcde,0jne r20;endcde=1call near ptr stor2cmp stustored,30ja oexitjmp continr20:call near ptr clsehcall clearcall cursorshowmsg 23jmp rexitoexit:call near ptr clsehmov saveflag,0showmsg 09;rexit:showmsg back;pop axretreadall endp;----------------------------------------------------------------------- readh proc nearpush axpush bxpush cxpush dxmov ah,3fh;read filemov bx,filehandlemov cx,17lea dx,stutempint 21hjc c1cmp ax,0je c2;ax=0,end of file,quitcmp stutemp,1ah;EOF Marker?je c2pop dxpop cxpop bxpop axretc1:lea dx,readmsgcall near ptr errmc2:mov endcde,1pop dxpop cxpop bxpop axretreadh endp;----------------------------------------------------------------------- save proc nearpush cxpush axmov errcde,0call near ptr clearcall near ptr cursorcall near ptr creathcmp errcde,0jne s2sloop:mov cx,stustoredcmp stusaved,cxje sexitcall near ptr writhcmp errcde,0jne sexitjmp sloopsexit:call near ptr clsehmov saveflag,1showmsg 07s2:showmsg exitanykeymov stusaved,0pop axpop cxretsave endp;------------------------------------------------------------------------ creath proc nearpush axpush cxpush dxshowmsg 21call near ptr get_pathcrlfmmov ah,3chmov cx,0lea dx,pathnamint 21hjc a1mov filehandle,axpop dxpop cxpop axreta1:lea dx,opnmsgcall errmpop dxpop cxpop axretcreath endp;------------------------------------------------------------------------ clseh proc nearpush axpush bxmov ah,3ehmov bx,filehandleint 21hpop bxpop axretclseh endp;------------------------------------------------------------------------ writh proc nearmov ax,stusavedmov bl,17mul bllea dx,studentxadd dx,ax;dxmov ah,40hmov bx,filehandlemov cx,17;cxint 21hinc stusavedjnc d1lea dx,wrtmsgcall near ptr errmd1:retwrith endp;------------------------------------------------------------------------ clear proc nearpush axpush bxpush cxpush dxmov AX,0600H ;clear screenmov CX,0mov DX,174FHmov BH,07int 10Hpop dxpop cxpop bxpop axretclear endp;------------------------------------------------------------------------ cursor proc nearpush axpush bxpush dxmov ah,2mov bh,0mov dx,0;dh:row,dl:columnint 10hpop dxpop bxpop axretcursor endpcode endsend start三.实验总结(心得、体会、实验设计不足之处)。
云南大学软件学院汇编语言实验报告五
练习:多字节的二进制加法程序实验
1.实验内容
将两个4字节长的二进制数相加,运算结果存放在相应结果单元中。
2.说明
首先应安排程序的结构,其中代码段和数据段是必须有的。
代码段里实现数的相加,可用带进位的加法指令;数据段中存放被加数、加数和结果单元这些数据。
考虑到编程的方便,在定义加数和被加数时,将低位字节放到低地址,高位字节放在高地址。
进行加法运算时,按照由低地址到高地址的顺序取得数据,而每一步运算的结果也按照低位放在低地,高位放在高地址的方式进行存储。
源程序:
DATAS SEGMENT
DATA1 DD AB464431H
DATA2 DDAC5434H
DATA3 DW 2 DUP(0);
DATAS ENDS
STACKS SEGMENT
STACKS ENDS
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
MOV AX,DATAS
MOV DS,AX
MOV BP,0
LEA SI,DATA1 ;
LEA DI,DATA2
MOV AX,[SI]
ADD AX,[DI] ;
JC L ;
MOV 4[DATA3],AX ;
MOV AX,0
LOOP1: MOV AX,4[SI] ;
ADD AX,4[DI]
JMP LOOP3
LOOP2: MOV AX,1 ;
JMP LOOP3
LOOP3: MOV [DATA3],AX ;
MOV AH,4CH
INT 21H
CODES ENDS
END START。
云南大学软件学院J2EE实验3
云南大学软件学院J2EE 实验报告姓名:学号:班级:日期:成绩:Lab 3 - Sharing Techniques一、实验目的1、进一步熟悉如何使用Eclipse开发Web应用;2、掌握不同页面间共享数据的四种方法:sendRidrect()、session、cookie和隐藏表单;3、理解sendRidrect()的交互流程;4、掌握使用session共享数据的方法;4、掌握HttpSession对象的相关知识;5、掌握使用cookie共享数据的方法;6、掌握HttpCookie对象的相关知识;。
二、实验步骤1、使用Eclipse建立Dynamic Web Project项目,命名为LoginV1.1;2、重构LoginV1的LoginCheck.java,使用sendRidrect()方法传递用户名和密码给LoginV1的Welcome.java;3、使用Eclipse建立Dynamic Web Project项目,命名为LoginV1.2;4、重构LoginV1.1的LoginCheck.java和Welcome.java文件,防止非法用户登录;5、开发SessionTest1和SessionTest2测试session对象;6、使用Eclipse建立Dynamic Web Project项目,命名为LoginV1.3;7、重构LoginV1.2的LoginCheck.java和Welcome.java文件,将用户信息放入session中;8、启动Tomcat,进行测试。
三、框架图1、LoginV1.1的框架图2、LoginV1.2的框架图2、LoginV1.3的框架图四、主要代码LoginV1.1的LoginCheck.java主要代码LoginV1.1的Welcome.java主要代码LoginV1.2的LoginCheck.java主要代码LoginV1.2的Welcome.javaLoginV1.3的LoginCheck.java的主要代码LoginV1.3的Welcome.java的主要代码LoginV1.3的Login.java的主要代码五、实验结果LoginV1.1登陆LoginV1.1登陆成功LoginV1.2登陆LoginV1.2登陆成功LoginV1.3的登陆成功LoginV1.3的Welcome页面点击返回登陆,取得session中的用户名和密码,并填到登陆输入框六、实验总结本次实验主要是对session进行了初步的了解和使用,了解了session在网站建设中的作用。
云南大学设计模式实验报告4_命令模式
云南大学软件学院实验报告序号:姓名:学号:专业:软件工程日期:2015.12.21 成绩:实验四命令模式的运用一、实验目的:命令模式将“请求”封装成对象,以便使用不同的请求、队列或者日志来参数化其他对象,命令模式也支持可撤销的操作。
在熟悉命令模式相关理论知识的基础上,使用命令模式实现图片处理程序。
二、实验要求:使用命令模式实现图片处理程序,要求如下:1.图片处理程序要有3张图片。
2.每张图片至少有3种操作。
3.实现类似遥控器的菜单,动态的选择对图片进行的处理。
4.要有“撤消操作”,撤消操作要可以撤销至最后一步。
1、设计并绘制该程序的类图;2、依照设计的类图使用Java语言编写代码,并实现该程序;3、除了核心的模式相关类实现外,提供测试环境,按照难度高低,分别是:a)控制台程序,Client硬编码初始化模式和测试环境,运行结果文本输出;b)控制台程序,Client初始化测试环境,并根据用户输入运算,运行结果文本输出;c)设计并实现用户UI,Client初始化测试环境,并根据用户在UI控件上的输入运算,运行结果文本输出;三、实验内容:实验类图:实验代码:1 DrawControl类public class DrawControl {ArrayList<DrawCommand> dcommand=new ArrayList<DrawCommand>();public void addCommand(DrawCommand dc){dcommand.add(dc);}public void removeCommand(DrawCommand dc){for(int i=0;i<dcommand.size();i++)if(dcommand.get(i).getClass().equals(getClass())){dcommand.remove(i);}}public void executeCommand(DrawCommand dc){for(int i=0;i<dcommand.size();i++)if(dcommand.get(i).getClass().equals(getClass())){dcommand.get(i).execute();}}public void undoCommand(DrawCommand dc){if (dcommand.size() > 1) {dcommand.get(dcommand.size() - 1).undo();dcommand.remove(dcommand.size() - 1);} elseSystem.out.println("Here is end, you can't undo");}}2 DrawCommand接口类package design4;interface DrawCommand {public void execute();public void undo();}3 Circular类public class Circular extends JPanel {Ellipse2D e =null;private int w,h;int f;public Circular(int w,int h){this.w=w;this.h=h;} //画圆型public void drawCircular(){e=new Ellipse2D.Double(w/2,h/4,50,50);f=1;repaint();} //画椭圆形public void drawEllipse(){e=new Ellipse2D.Double(w/2,h/4,20,70);f=1;repaint();} //画实心圆public void drawSolidRound(){f=2;e=new Ellipse2D.Double(w/2,h/4,50,50);repaint();}public void paintComponent(Graphics g){super.paintComponent(g);if(f==1){Graphics2D g2=(Graphics2D) g;g2.draw(e);}else{Graphics2D g2=(Graphics2D) g;//g2.draw(e);g2.setPaint(Color.RED);g2.fill(e);}}}4 Circular Command类package design4;public class CircularCommand implements DrawCommand{ Circular circular;public CircularCommand(Circular c){circular=c;}public void execute() {circular.drawCircular();}public void undo() {// TODO Auto-generated method stub}}5 DrawJFrampackage design4;import java.awt.Container;import java.awt.GridLayout;import java.awt.Panel;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JComboBox;import javax.swing.JFrame;import javax.swing.JLabel;public class DrawJFram extends JFrame implements ActionListener{JComboBox comboBox,comboBox2,comboBox3;String[] str={"圆形","椭圆","实心圆"};String[] str2={"方形","正方形","长方形"};String[] str3={"三角形","等腰直角三角形","等边三角形"};public DrawJFram (){super(" ");this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setcomputerWindow();}private void setcomputerWindow() {// TODO Auto-generated method stub Container ct=this.getContentPane();Container ct=this.getContentPane();ct.setLayout(new GridLayout(6,1));Panel p1=new Panel();p1.add(new JLabel("圆形:"));comboBox=new JComboBox(str);p1.add(comboBox);p1.add(new JLabel("方形:"));comboBox2=new JComboBox(str2);p1.add(comboBox2);p1.add(new JLabel("三角形:"));comboBox3=new JComboBox(str3);p1.add(comboBox3);comboBox.addActionListener(this);comboBox2.addActionListener(this);comboBox3.addActionListener(this);ct.add(p1,"North");}public void actionPerformed(ActionEvent e) {if(e.getSource().equals(comboBox)){if(comboBox.getSelectedItem().equals("圆形")){Circular circular=new Circular(100, 100);this.add(circular,"South");circular.drawCircular();this.setVisible(true);}else if(comboBox.getSelectedItem().equals("椭圆")){Circular circular=new Circular(30, 70);this.add(circular,"South");circular.drawEllipse();this.setVisible(true);}else if(comboBox.getSelectedItem().equals("实心圆")){Circular circular=new Circular(50, 50);this.add(circular,"South");circular.drawSolidRound();this.setVisible(true);}}else if(e.getSource().equals(comboBox2)){if(comboBox2.getSelectedItem().equals("方形")){Rectangle rectangle=new Rectangle(100, 100);this.add(rectangle,"South");rectangle.drawhighRectangle();this.setVisible(true);}else if(comboBox2.getSelectedItem().equals("长方形")){ Rectangle rectangle=new Rectangle(100, 100);this.add(rectangle,"South");rectangle.drawlongRectangle();this.setVisible(true);}else if(comboBox2.getSelectedItem().equals("正方形")){ Rectangle rectangle=new Rectangle(100, 100);this.add(rectangle,"South");rectangle.drawsquare();this.setVisible(true);}}else if(e.getSource().equals(comboBox3)){if(comboBox3.getSelectedItem().equals("三角形")){Triangle triangle=new Triangle(500, 10);this.add(triangle,"South");triangle.drawTriangle();this.setVisible(true);}else if(comboBox3.getSelectedItem().equals("等腰直角三角形")){ Triangle triangle=new Triangle(500, 30);this.add(triangle,"South");triangle.drawIsoscelesTriangle();this.setVisible(true);}else if(comboBox3.getSelectedItem().equals("等边三角形")){ Triangle triangle=new Triangle(500, 50);this.add(triangle);triangle.draweQuilateralTriangle();this.setVisible(true);}}}}6 pictureMainpackage design4;import java.awt.Dimension;import java.awt.Toolkit;public class pictureMain {public static void main(String[] args) {// TODO Auto-generated method stubToolkit kit=Toolkit.getDefaultToolkit();Dimension screenSize=kit.getScreenSize();int screenHeihgt=screenSize.height;int screenWidth=screenSize.width;DrawJFram drawJFram=new DrawJFram();drawJFram.setSize(screenWidth,screenHeihgt);drawJFram.setVisible(true);}}实验结果四、实验总结:我经过本次命令模式的实验,通过自己动手编代码,是自己理解命令模式机制,并且知道命令模式有以下的优点:适用性:想要实现回调函数功能,想要在不同的时刻指定、排列和执行请求,需要支持取消和改变日志操作;效果:命令模式将调用操作的对象与知道如何实现该操作的对象解耦,Command是头等的对象。
实验报告(实验二:一元稀疏多项式计算器)
云南大学软件学院实验报告指导教师:朱艳萍 2009秋季学期学号:20081120064 姓名:李雪寒【实验题目】实验2. 一元稀疏多项式简单计算器【问题描述】设计并实现一个一元稀疏多项式的简单计算器。
【基本要求】一元稀疏多项式简单计算器的基本功能是:1.输入并建立多项式;2.输出多项式,序列按指数降序排列;3.多项式a和b相加,并建立多项式a+b;4.多项式a和b相减,并建立多项式a-b;【实现提示】1.用带头节点的单链表作为多项式的存储结构;一、【概要设计】链式存储结构,由于不要求逻辑上相邻的元素在物理上也相邻,因此,能够迅速进行插入或删除操作,而且不像顺序存储结构那样需要移动大量元素,但也没有顺序表那样随机存取的优点。
主程序中通过调用void create(polynmial &L) 创建存储在单链表中的多项式,调用void display(polynmial L); 输出显示多项式,调用void sort(polynmial &L)和void reverse(polynmial &L)对多项式进行排序,使其按降序排列,调用void add(polynmial La,polynmial Lb, polynmial &Lc) 和void subtract(polynmial La, polynmial Lb, polynmial &Ld) 对两个多项式进行加减操作。
二、【详细设计】在此次试验中,主要通过以下7个子函数对存储在单链表中的多项式进行操作:void create(polynmial &L) //输入并建立多项式L{int i, n;static struct node *p;printf("输入多项式项数:\n");scanf("%d", &n);//输入多项式的项数L = (struct node *)malloc (sizeof(struct node));L->next = NULL;for(i = 0; i < n; i++){p = (struct node *)malloc(sizeof(struct node));printf("输入一个项的系数和指数,用空格隔开:\n");scanf("%f %d", &p->c, &p->e);p->next = L->next;L->next = p;}//利用for循环输入多项式中每一项的系数和指数}void display(polynmial L)//显示,输出多项式L{struct node *p, *q;//建立两个结点int flag = 0;int k = 0;q = L->next;while(q){if(q->c!= 0)k++;//计算多项式的项数q = q->next;}printf("共%d项\n", k);//输出多项式的项数p = L->next;if(p->c != 0){printf("+%.1fx^%d", p->c, p->e);flag++;}//判断该项是否为零,不为零则输出for(p = p->next; p; p = p->next){if(p->c != 0){printf("+%.1fx^%d", p->c, p->e);flag++;}}//输出多项式if(flag == 0)printf("%d\n", flag);elseprintf("\n");}void sort(polynmial &L)//多项式L按指数排序{polynmial p, q, r, s;p = L->next;L->next = NULL;while(p != NULL){r = L;q = L->next;while((q != NULL) && (q->e <= p->e)){r = q;q = q->next;}s = p->next;r->next = p;p->next = q;p = s;}}void reverse(polynmial &L)//逆置{polynmial H;static struct node *p, *q, *s;H = (struct node*)malloc(sizeof(struct node));H->next = NULL;p = (struct node*)malloc(sizeof(struct node));s = L->next;p->c = s->c;p->e = s->e;p->next = s->next;while(s){p->c = s->c;p->e = s->e;p->next = s->next;q = H->next;H->next = p;p->next = q;p = (struct node*)malloc(sizeof(struct node));s = s->next;}p = H->next;q = L->next;while(p){q->c = p->c;q->e = p->e;q = q->next;p = p->next;}}void select() //用户选择加减操作{printf("请选择加减操作\n");printf("1.两个一元多项式相加\n");printf("2.两个一元多项式相减\n");}void add(polynmial La, polynmial Lb, polynmial &Lc)//多项式La,Lb相加,并付给Lc {struct node *pa, *pb;static struct node *pc;Lc = (struct node*)malloc(sizeof(struct node));pa = La->next;pb = Lb->next;Lc->next = NULL;while(pa && pb){pc = (struct node*)malloc(sizeof(struct node));if(pa->e < pb->e){pc->next = Lc->next;Lc->next = pc;pc->c = pa->c;pc->e = pa->e;pa = pa->next;}elseif(pa->e == pb->e){pc->next = Lc->next;Lc->next = pc;pc->e = pa->e;pc->c = pa->c + pb->c;pa = pa->next;pb = pb->next;}else{pc->next = Lc->next;Lc->next = pc;pc->c= pb->c;pc->e = pb->e;pb = pb->next;}}while(pa){pc = (struct node*)malloc(sizeof(struct node));pc->next = Lc->next;Lc->next = pc;pc->c = pa->c;pc->e = pa->e;pa = pa->next;}while(pb){pc = (struct node*)malloc(sizeof(struct node));pc->next = Lc->next;Lc->next = pc;pc->c = pb->c;pc->e = pb->e;pb = pb->next;}}void subtract(polynmial La, polynmial Lb, polynmial &Ld)//多项式La减去Lb,结果赋给Ld{struct node *pa, *pb;static struct node *pd;Ld = (struct node*)malloc(sizeof(struct node));pa = La->next;pb = Lb->next;Ld->next = NULL;while(pa && pb){pd = (struct node*)malloc(sizeof(struct node));if(pa->e< pb->e){pd->next = Ld->next;Ld->next = pd;pd->c= pa->c;pd->e = pa->e;pa = pa->next;}elseif(pa->e == pb->e){pd->next = Ld->next;Ld->next = pd;pd->e= pa->e;pd->c = pa->c - pb->c;pa = pa->next;pb = pb->next;}else{pd->next = Ld->next;Ld->next = pd;pd->c = pb->c;pd->e = pb->e;pb = pb->next;}}while(pa){pd = (struct node*)malloc(sizeof(struct node));pd->next = Ld->next;Ld->next = pd;pd->c = pa->c;pd->e = pa->e;pa = pa->next;}while(pb){pd = (struct node*)malloc(sizeof(struct node));pd->next = Ld->next;Ld->next = pd;pd->c = -pb->c;pd->e = pb->e;pb = pb->next;}}三、【测试结果】四、【实验总结】此次实验较实验一来说要难得多,算法也复杂得多,原因主要有:1、C语言的应用很生疏,有待加强;2、对于单链表的插入和删除操作不熟练,需要借助课本和资料进行参考;3、程序比较复杂,算法思想也很难理清,需要多加锻炼。
云南大学--软件学院--大学物理实验2
课程:大学物理实验学期:2009-2010学年第一学期任课教师:
班级:学号:序号: 姓名:成绩:
实验2质点运动学
一、实验内容1
1.证明公式: ,有关各个变量的定义见实验内容。
2.设定并记录发现目标距离、目标飞行高度、目标飞行速度;
发现目标距离
目标飞行高度
目标飞行速度
10000
11.45
11.44
11.43
11.42
11.423
水平误差
(米)Biblioteka 154.6137.4120.2
114.2
68.7
25.3
16.2
7.1
-2.0
1.0
观察角2= 16.820(度)
实验
1
2
3
4
5
6
7
8
9
10
发射角
(度)
33.5
33.3
32.9
32.7
32.3
32
31.9
31.5
31.4
31
水平误差
(米)
1000
500
3.根据程序显示的不同观察角,选定10个不同的拦截发射角,记录各个拦截发射角对应的拦截弹头与目标的水平误差;并分析拦截发射角等于多少,水平误差最小?记录2个不同观测角的情况。
观察角1= 5.834度)
实验
1
2
3
4
5
6
7
8
9
10
发射角
(度)
11.6
11.58
11.56
11.555
11.5
177.0
156.1
112.3
88.6
云南大学软件学院汇编语言实验报告三
五、练习
1. 已知程序段定义如下:
MOV AX,1234
MOV CL,4
SHL AX,CL
INC AX
DEC CL
ROR AX,CL
MOV BX,4
MUL BX
MOV BX,4
DIV BX
INT 20
(1)每条指令执行后,AX寄存器中的内容是什么?
(2)每条指令执行后,标志寄存器的各位标志等于什么?
(3)程序结束时,AX和DX的内容等于什么?
2. 编写一程序求双字数据的绝对值。
双字数据保存在DX和AX中,结果保存在BX和CX中。
3. 编制程序,将DX和AX中的双字右移4位。
mov ch,4
go: shr dx,1
rcr ax,1
dec ch
jnz go
4. 编制程序,判断DL寄存器的低4位是否全为0?是否有0?判断AL寄存器中的数值是奇数还是偶数?是否为4的倍数?
6. 编制程序,用一条指令让AX寄存器清0;用一条指令使DX寄存器高3位为1,其余位保持不变;用一条指令使BL寄存器低4位为0,其余位保持不变;用一条指令,使SI和DI寄存器中对应位不相同的位置均置1;
7. 从内存3000H开始的单元中顺序存放着40个同学某门课的考试成绩,试编写程序段求该班该门课的总成绩和平均成绩。
云南大学软件学院PKI体系与CA技术实验2
云南大学软件学院实验报告课程:PKI体系与CA技术学期:2015-2016学年第二学期任课教师:刘璟专业:信息安全学号219 姓名:刘宁宁成绩:实验2 使用OpenSSL创建自己的签证中心实验时间:实验地点:软件大楼1428 ;注意:实验报告统一命名为:学号姓名实验1.docx,例如:学号为203的张三同学提交的实验报告应该命名为:203张三实验1.docx一、实验目的1. 学会开源软件OpenSSL的编译和安装,从而掌握一般开源软件的编译和安装方法(指Unix系统下的开源软件的编译和安装方法)。
2. 使用OpenSSL创建自己的签证(CA)中心。
3. 学会使用OpenSSL来管理数字证书的整个生命周期。
4. 熟悉OpenSSL,为以后在OpenSSL基础上做进一步的编程开发工作打下基础。
二、实验内容1. 在Windows环境下编译和安装开源软件OpenSSL,掌握围绕makefile文件的软件编译和安装方法。
2. 应用OpenSSL来创建自己的签证(CA)中心:1)为签证中心创建工作环境;2)研究OpenSSL配置文件,并创建一个自己的OpenSSL配置文件;3)生成CA自签名的根证书,并了解CA自签名根证书的作用。
4)为用户签发(颁发)数字证书;5)吊销已签发的数字证书。
三、详细实验步骤(关键步骤请截屏)1.openssl的安装:Perl安装完成:为Visual Studio 2010(Visual C++)设置临时环境变量:执行如下Configure命令(该步骤的目的是配置编译参数,对编译环境进行基本的配置):perl Configure VC-WIN32至此,openssl的配置完成。
2.使用openssl创建自己的签证中心建立CA目录:创建OpenSSL配置文件:修改req项里面的内容:运行命令:C:\CARoot>openssl req -x509 -newkey rsa -out private\cacert.pem -outform PEM在命令行输入C:\CARoot> openssl ca -in testreq.pem生成了一个名为“01.pem”的数字证书4、吊销已经签发的数字证书:如下命令:C:\CARoot>openssl ca -revoke newcerts\01.pem生成一个证书吊销列表exampleca.crl:C:\CARoot>openssl ca -gencrl -out exampleca.crl输入命令:C:\CARoot>openssl crl -in exampleca.crl -text -noout成功吊销证书,显示verify OK:四、实验总结通过回答以下几个问题来进行总结:1.实验一种我们从沃通官网下载的数字证书格式为PFX,在本实验中我们使用OpenSSL生成的数字证书格式为PEM,试比较两种证书格式的异同?答:该编码格式在RFC1421中定义,其实PEM是Privacy-Enhanced Mail的简写,但他也同样广泛运用于密钥管理,一般基于base 64编码。
云南大学软件学院计算机网络原理实验六实验报告3
实验六、传输层可靠传输协议GBN编程实验报告序号:姓名:学号:成绩指导老师:一、实验目的:1、通过编写实现一个简单可靠的数据传输协议GBN的发送和接收代码,模拟可靠数据传输2、理解TCP协议可靠传输的差错检测、重传、累计确认、定时器的可靠传输策略。
二、实验指导:参考教材。
动画演示:三、实验要求:编程实现一个GBN传输协议的发送方和接收方两程序,采用编程语言不限,要求能将发送――接收流程以及处理方法表现出来.1.实验流程图如下:N2.实验截图与代码如下: 截图: 传送下一个数据包结束代码及注释:一、GBN.h#pragma once#include <stdio.h>//基础功能模块的数据结构声明#define BIDIRECTIONAL 1 /* change to 1 if you're doing extra credit andwrite a routine called B_output *//* a "msg" is the data unit passed from layer 5 (teachers code) to layer4 (students' code). It contains the data (characters) to be delivered tolayer 5 via the students transport level protocol entities. */struct msg{ char data[20];};/* a packet is the data unit passed from layer 4 (students code) to layer3 (teachers code). Note the pre-defined packet structure, which allstudents must follow. */struct pkt{int seqnum;int acknum;int checksum;char payload[20];};#define WINDOWSIZE 8#define MAXBUFSIZE 50#define RTT 15.0#define NOTUSED 0#define NACK -1#define TRUE 1#define FALSE 0#define A 0#define B 1//网络仿真部分数据结构声明***********************************************************struct event{float evtime; /* event time */int evtype; /* event type code */int eventity; /* entity where event occurs */struct pkt *pktptr; /* ptr to packet (if any) assoc w/ this event */ struct event *prev;struct event *next;};/* possible events: */#define TIMER_INTERRUPT 0#define FROM_LAYER5 1#define FROM_LAYER3 2#define OFF 0#define ON 1//基础功能模块的函数声明******************************************************************* void ComputeChecksum(struct pkt *packet);//计算校验和int CheckCorrupted(struct pkt packet);//检查数据是否出错void A_output( struct msg message);//A端向外发送数据void A_input(struct pkt packet);//A端接收数据void A_timerinterrupt();//A计时器超时void A_init();//A端初始化void B_output(struct msg message);void B_input(struct pkt packet);void B_timerinterrupt();void B_init();//网络仿真部分的函数声明**************************************************void init(); //初始化仿真器float jimsrand();//随机数发生器[0,1]//处理事件列表部分的函数声明*********************************************void generate_next_arrival();//产生下一个到达的分组void insertevent(struct event *p);//向事件列表中插入一条新的事件void printevlist();//打印事件列表//******************************************************************** //**********************计时器模块*********************************** void stoptimer(int);//停止计时器void starttimer(int,float);//启动计时器//******************************************************************** *//**************************网络各层之间传送模块***********************void tolayer3(int AorB,struct pkt packet);//向第3层发送信息void tolayer5(int AorB,char datasent[20]);//向第5层发送信息二、GBN.c#include "GBN.h"#include <stdio.h>#include <string.h>#include <stdlib.h>extern int TRACE = 1; /* for my debugging */为我的调试extern int nsim = 0; /* number of messages from 5 to 4 so far */目前为止信息的数字是从5到4extern int nsimmax = 0; /* number of msgs to generate, then stop */如果信息产生的数字为0,然后就停止extern float time = 0.000;float lossprob; /* probability that a packet is dropped */数据包可能会丢失float corruptprob; /* probability that one bit is packet is flipped*/这一点的数据包可能会被弹出去float lambda; /* arrival rate of messages from layer 5 */ 第五层到达的信息的次序int ntolayer3; /* number sent into layer 3 */被传送到第三层的数据static int nlost = 0; /* number lost in media */在媒介中数据丢失static int ncorrupt = 0; /* number co rrupted by media*/被媒介毁坏的数据static int expectedseqnum = 0; /* expected se quence number at receiver side */在接收者这边接收到预期的序列数据static int nextseqnum; /* next sequence number to use in sender side */下一个序列数据使用在发送者这边static int base; /* t he head of sender window */发送者的头窗口struct pkt winbuf[WINDOWSIZE]; /* window packets buffer */数据包缓冲区窗口static int winfront,winrear; /* front and rear points of wind ow buffer */窗口缓冲区的前方点和后方点static int pktnum; /* packet number of window buffer */窗口缓冲区的数据包个数struct msg buffer[MAXBUFSIZE]; /* sender message buffer */发送消息缓冲区int buffront,bufrear; /* front and rear pointers of buffer */缓冲区的前指针与后指针static int msgnum; /* message number of buffer */信息数量的缓冲int packet_lost =0;int packet_corrupt=0;int packet_sent =0;extern int packet_correct=0;extern int packet_resent =0;int packet_timeout=0;extern struct event *evlist = NULL; /* the event list *///计算校验和void ComputeChecksum( struct pkt *packet){int checksum;int i;checksum = packet->seqnum;checksum = checksum + packet->acknum;for ( i=0; i<20; i++ )checksum = checksum + (int)(packet->payload[i]);checksum = 0-checksum;packet->checksum = checksum;}//检查是否出错int CheckCorrupted(struct pkt packet){int checksum;int i;checksum = packet.seqnum;checksum = checksum + packet.acknum;for ( i=0; i<20; i++ )checksum = checksum + (int)(packet.payload[i]);if ( (packet.checksum+checksum) == 0 )return (FALSE);elsereturn (TRUE);}//A端向外发送数据/* called from layer 5, passed the data to be sent to other side */ void A_output(struct msg message){int i;struct pkt sendpkt;/* if window is not full */if ( nextseqnum < base+WINDOWSIZE ){printf("----A: New message arrives, send window is not full, send new messge to layer3!\n");/* create packet */sendpkt.seqnum = nextseqnum;sendpkt.acknum = NOTUSED;for ( i=0; i<20 ; i++ )sendpkt.payload[i] = message.data[i];/* computer checksum */ComputeChecksum (&sendpkt);/* send out packet */tolayer3 (A, sendpkt);/* copy the packet to window packet buffer */winrear = (winrear+1)%WINDOWSIZE;pktnum ++;winbuf[winrear] = sendpkt;for (i=0; i<20; i++)winbuf[winrear].payload[i]= sendpkt.payload[i];/* update state variables */nextseqnum = nextseqnum+1;starttimer(A,RTT);B_input(sendpkt);A_input(sendpkt);}/* if window is full */else{printf("----A: New message arrives, send window is full,");/* if buffer full, give up and exit*/if ( msgnum == MAXBUFSIZE){printf (" Error: Sender buffer is full! \n");exit (1);}/* otherwise, buffer the message */else{printf("buffer new message!\n");bufrear = (bufrear+1) % MAXBUFSIZE;for (i=0; i<20; i++)buffer[bufrear].data[i] = message.data[i];msgnum ++;}}}//B端向外发送数据/* called from layer 5, passed the data to be sent to other side */ void B_output(struct msg message){int i;struct pkt sendpkt;/* if window is not full */if ( nextseqnum < base+WINDOWSIZE ){printf("----A: New message arrives, send window is not full, send new messge to layer3!\n");/* create packet */sendpkt.seqnum = nextseqnum;sendpkt.acknum = NOTUSED;for ( i=0; i<20 ; i++ )sendpkt.payload[i] = message.data[i];/* computer checksum */ComputeChecksum (&sendpkt);/* send out packet */tolayer3 (A, sendpkt);A_input(sendpkt);/* copy the packet to window packet buffer */winrear = (winrear+1)%WINDOWSIZE;pktnum ++;winbuf[winrear] = sendpkt;for (i=0; i<20; i++)winbuf[winrear].payload[i]= sendpkt.payload[i];/* if it is the first packet in window, start timeout */ //if ( base == nextseqnum )//{//starttimer(A,RTT);//printf("----A: start a new timer!\n");// }/* update state variables */nextseqnum = nextseqnum+1;}/* if window is full */else{printf("----A: New message arrives, send window is full,");/* if buffer full, give up and exit*/if ( msgnum == MAXBUFSIZE){printf (" Error: Sender buffer is full! \n");exit (1);}/* otherwise, buffer the message */else{printf("buffer new message!\n");bufrear = (bufrear+1) % MAXBUFSIZE;for (i=0; i<20; i++)buffer[bufrear].data[i] = message.data[i];msgnum ++;}}}//A端接收数据void A_input(struct pkt packet){struct pkt sendpkt;int i;/* if received packet is not corrupted and ACK is received */if ( (CheckCorrupted(packet) == FALSE) && (packet.acknum != NACK) ) {printf("----A: ACK %d is correctly received,",packet.acknum);packet_correct++;/* delete the acked packets from window buffer */winfront = (winfront+(packet.acknum+1-base)) % WINDOWSIZE; pktnum = pktnum - (packet.acknum+1-base);/* move window base */base = packet.acknum+1;stoptimer(A);if ( base < nextseqnum){//starttimer(A,RTT);printf ("\n\n\nsend new packets!");}/* if buffer is not empty, send new packets */while ( (msgnum!=0) && (nextseqnum<base+WINDOWSIZE) ) {/* create packet */sendpkt.seqnum = nextseqnum;sendpkt.acknum = NOTUSED;buffront = (buffront+1) % MAXBUFSIZE;for ( i=0; i<20 ; i++ )sendpkt.payload[i] = buffer[buffront].data[i];/* computer checksum */ComputeChecksum (&sendpkt);/* if it is the first packet in window, start timeout */if ( base == nextseqnum ){//starttimer(A,RTT);printf ("send new packets!\n");}/* send out packet */tolayer3 (A, sendpkt);/* copy the packet to window packet buffer */winrear = (winrear+1)%WINDOWSIZE;winbuf[winrear] = sendpkt;pktnum ++;/* update state variables */nextseqnum = nextseqnum+1;/* delete message from buffer */msgnum --;}}elseprintf ("----A: NACK is received, do nothing!\n");}//B端接收数据*****************************************************一定要调用这个/* Note that with simplex transfer from a-to-B, there is no B_output() */ /* called from layer 3, when a packet arrives for layer 4 at B*/void B_input(struct pkt packet){struct pkt sendpkt;int i;/* if not corrupted and received packet is in order */if ( (CheckCorrupted(packet) == FALSE) && (packet.seqnum == expectedseqnum)){printf("\n----B: packet %d is correctly received, send ACK!\n",packet.seqnum);/* send an ACK for the received packet *//* create packet */sendpkt.seqnum = NOTUSED;sendpkt.acknum = expectedseqnum;for ( i=0; i<20 ; i++ )sendpkt.payload[i] = '0';/* computer checksum */ComputeChecksum (&sendpkt);/* send out packet *///tolayer3 (B, sendpkt);/* update state variables */expectedseqnum = expectedseqnum+1;printf("----B:expectedseqnum = %d\n",expectedseqnum);/* deliver received packet to layer 5 *///tolayer5(B,packet.payload);}/* otherwise, discard the packet and send a NACK */else{printf("----B: packet %d is corrupted or not I expects, send NACK!\n",packet.seqnum);/* create packet */sendpkt.seqnum = NOTUSED;sendpkt.acknum = NACK;for ( i=0; i<20 ; i++ )sendpkt.payload[i] = '0';/* computer checksum */ComputeChecksum (&sendpkt);/* send out packet */tolayer3 (B, sendpkt);}}//A计时器超时/* called when A's timer goes off */void A_timerinterrupt(){int i;printf("----A: time out,resend packets!\n");/* start timer */starttimer(A,RTT);/* resend all packets not acked */for ( i=1; i<=pktnum; i++ ){packet_resent++;tolayer3(A,winbuf[(winfront+i)%WINDOWSIZE]);}}//B计时器超时/* called when B's timer goes off */void B_timerinterrupt(){int i;printf("----B: time out,resend packets!\n");/* start timer */starttimer(B,RTT);/* resend all packets not acked */for ( i=1; i<=pktnum; i++ ){packet_resent++;tolayer3(B,winbuf[(winfront+i)%WINDOWSIZE]);}}//A端初始化/* entity A routines are called. You can use it to do any initialization */void A_init()base = 0;nextseqnum = 0;buffront = 0;bufrear = 0;msgnum = 0;winfront = 0;winrear = 0;pktnum = 0;}//B端初始化/* entity B routines are called. You can use it to do any initialization */void B_init(){expectedseqnum = 0;}//初始化仿真器void init() /* initialize the simulator */{int i;float sum, avg;float jimsrand();FILE *fp;fp = fopen ("parameter.txt","r");printf("----- Stop and Wait Network Simulator Version 1.1 -------- \n\n");printf("Enter the number of messages to simulate: ");//fscanf(fp,"%d",&nsimmax);scanf("%d",&nsimmax);printf("\nEnter packet loss probability [enter 0.0 for no loss]: "); //fscanf(fp, "%f",&lossprob);scanf("%f",&lossprob);printf("\nEnter packet corruption probability [0.0 for no corruption]: "); //fscanf(fp,"%f",&corruptprob);scanf("%f",&corruptprob);printf("\nEnter average time between messages from sender's layer5 [ > 0.0]: ");//fscanf(fp,"%f",&lambda);scanf("%f",&lambda);printf("\nEnter TRACE: ");//fscanf(fp,"%d",&TRACE);scanf("%d",&TRACE);printf("\n\n");srand(9999); /* init random number generator */sum = 0.0; /* test random number generator for students */for (i=0; i<1000; i++)sum=sum+jimsrand(); /* jimsrand() should be uniform in [0,1] */avg = sum/1000.0;/*if(avg < 0.25 || avg > 0.75){printf("It is likely that random number generation on your machine\n" ); printf("is different from what this emulator expects. Please take\n"); printf("a look at the routine jimsrand() in the emulator code. Sorry. \n");exit(0);}*/printf("%f",avg);ntolayer3 = 0;nlost = 0;ncorrupt = 0;time=0.0; /* initialize time to 0.0 */generate_next_arrival(); /* initialize event list */}//随机数发生器float jimsrand(){double mmm = 2147483647; /* largest int - MACHINE DEPENDENT */float x; /* individual students may need to change mmm */x = rand()/mmm; /* x should be uniform in [0,1] */return(x);}//**************************************************************************************//*******************************事件处理部分*******************************************void generate_next_arrival(){double x,log(),ceil();struct event *evptr;float ttime;int tempint;//if (TRACE>2)//printf("-----------------GENERATE NEXT ARRIVAL: creating new arrival\n");x = lambda*jimsrand()*2; /* x is uniform on [0,2*lambda] *//* having mean of lambda */evptr = (struct event *)malloc(sizeof(struct event));evptr->evtime = time + x;evptr->evtype = FROM_LAYER5;if (jimsrand()<0.5){evptr->eventity = A;}evptr->eventity = B;insertevent(evptr);}//向事件列表中插入一条新的事件void insertevent(struct event *p){struct event *q,*qold;if (TRACE>2){//printf(" INSERTEVENT: time is %lf\n",time);//printf(" INSERTEVENT: future time will be %lf\n",p->evtime);}q = evlist; /* q points to front of list in which p struct inserted */if (q==NULL)/* list is empty */{evlist=p;p->next=NULL;p->prev=NULL;}else{for (qold = q; q !=NULL && p->evtime > q->evtime; q=q->next) qold=q;if (q==NULL)/* end of list */{qold->next = p;p->prev = qold;p->next = NULL;}else if (q==evlist)/* front of list */p->next=evlist;p->prev=NULL;p->next->prev=p;evlist = p;}else /* middle of list */{p->next=q;p->prev=q->prev;q->prev->next=p;q->prev=p;}}}//打印事件列表void printevlist(){struct event *q;int i;printf("--------------\nEvent List Follows:\n");for(q = evlist; q!=NULL; q=q->next){printf("Event time: %f, type: %d entity: %d\n",q->evtime,q->evtype,q->eventity);}printf("--------------\n");}//启动计时器void starttimer(int AorB,float increment){struct event *q;struct event *evptr;if (TRACE>2)printf("\n----A: START TIMER: starting timer at %f\n",time);/* be nice: check to see if timer is already started, if so, then warn *//* for (q=evlist; q!=NULL && q->next!=NULL; q = q->next) */for (q=evlist; q!=NULL ; q = q->next)if ( (q->evtype==TIMER_INTERRUPT && q->eventity==AorB) ){//printf("Warning: attempt to start a timer that is already started\n");return;}/* create future event for when timer goes off */evptr = (struct event *)malloc(sizeof(struct event));evptr->evtime = time + increment;evptr->evtype = TIMER_INTERRUPT;evptr->eventity = AorB;insertevent(evptr);}//停止计时器/* called by students routine to cancel a previously-started timer */ void stoptimer(int AorB) /* A or B is trying to stop timer */{struct event *q,*qold;if (TRACE>2)printf("\n----A: STOP TIMER: stopping timer\n");/* for (q=evlist; q!=NULL && q->next!=NULL; q = q->next) */for (q=evlist; q!=NULL ; q = q->next)if ( (q->evtype==TIMER_INTERRUPT && q->eventity==AorB) )/* remove this event */{if (q->next==NULL && q->prev==NULL)evlist=NULL; /* remove first and only event on listelse if (q->next==NULL) /* end of list - there is one in front */ q->prev->next = NULL;else if (q==evlist) /* front of list - there must be event after */{q->next->prev=NULL;evlist = q->next;}else /* middle of list */{q->next->prev = q->prev;q->prev->next = q->next;}free(q);return;}//printf("Warning: unable to cancel your timer. It wasn't running.\n");}//向第三层发送信息/************************** TOLAYER3 ***************/void tolayer3(int AorB,struct pkt packet){struct pkt *mypktptr;struct event *evptr,*q;float lastime, x, jimsrand();int i;ntolayer3++;/* simulate losses: */if (jimsrand() < lossprob){nlost++;if (TRACE>0)printf(" TOLAYER3: packet being lost\n");return;}/* make a copy of the packet student just gave me since he/she may decide *//* to do something with the packet after we return back to him/her */ mypktptr = (struct pkt *)malloc(sizeof(struct pkt));mypktptr->seqnum = packet.seqnum;mypktptr->acknum = packet.acknum;mypktptr->checksum = packet.checksum;for (i=0; i<20; i++)mypktptr->payload[i] = packet.payload[i];if (TRACE>2){printf(" TOLAYER3: seq: %d, ack %d, check: %d ", mypktptr->seqnum,mypktptr->acknum, mypktptr->checksum);for (i=0; i<20; i++)printf("%c",mypktptr->payload[i]);printf("");}/* create future event for arrival of packet at the other side */evptr = (struct event *)malloc(sizeof(struct event));evptr->evtype = FROM_LAYER3; /* packet will pop out from layer3 */ evptr->eventity = (AorB) % 2; /* event occurs at other entity */evptr->pktptr = mypktptr; /* save ptr to my copy of packet *//* finally, compute the arrival time of packet at the other end. medium can not reorder, so make sure packet arrives between 1 and 10 time units after the latest arrival time of packetscurrently in the medium on their way to the destination */lastime = time;/* for (q=evlist; q!=NULL && q->next!=NULL; q = q->next) */for (q=evlist; q!=NULL ; q = q->next)if ( (q->evtype==FROM_LAYER3 && q->eventity==evptr->eventity) ) lastime = q->evtime;evptr->evtime = lastime + 1 + 9*jimsrand();/* simulate corruption: */if (jimsrand() < corruptprob){ncorrupt++;if ( (x = jimsrand()) < .75)mypktptr->payload[0]='Z'; /* corrupt payload */else if (x < .875)mypktptr->seqnum = 999999;elsemypktptr->acknum = 999999;if (TRACE>0)printf(" TOLAYER3: packet being corrupted\n");}//if (TRACE>2)//printf(" TOLAYER3: scheduling arrival on other side\n");insertevent(evptr);}//向第五层发送信息/************************** TOLAYER5 ***************/void tolayer5(int AorB,char datasent[20]){int i;if (TRACE>2){printf(" TOLAYER5: data received: ");for (i=0; i<20; i++)printf("%c",datasent[i]);printf("\n");}}三、GBN-CS.c#include "GBN.h"#include <stdio.h>#include <string.h>#include <stdlib.h>extern int TRACE ; /* for my debugging */extern int nsim ; /* number of messages from 5 to 4 so far */extern int nsimmax; /* number of msgs to generate, then stop */extern float time;extern int packet_correct;extern int packet_resent;extern struct event *evlist;int main(){struct event *eventptr;struct msg msg2give;struct pkt pkt2give;int i,j;char c;init();A_init();B_init();while (1){eventptr = evlist; /* get next event to simulate */ if (eventptr==NULL)goto terminate;evlist = evlist->next; /* remove this event from event list */if (evlist!=NULL)evlist->prev=NULL;if (TRACE >= 2){printf("\nEVENT time: %f,",eventptr->evtime);printf(" type: %d",eventptr->evtype);if (eventptr->evtype==0)printf(", timerinterrupt ");else if (eventptr->evtype==1)printf(", fromlayer5 ");elseprintf(", fromlayer3 ");printf(" entity: %d\n",eventptr->eventity);}time = eventptr->evtime; /* update time to next event time*/if (nsim==nsimmax)break; /* all done with simulation */if (eventptr->evtype == FROM_LAYER5 ){generate_next_arrival(); /* set up future arrival *//* fill in msg to give with string of same letter */j = nsim % 26;for (i=0; i<20; i++)msg2give.data[i] = 97 + j;if (TRACE>2){printf(" MAINLOOP: data given to student: ");for (i=0; i<20; i++)printf("%c", msg2give.data[i]);printf("\n");}nsim++;if (eventptr->eventity == A){A_output(msg2give);}else{B_output(msg2give);}}else if (eventptr->evtype == FROM_LAYER3){pkt2give.seqnum = eventptr->pktptr->seqnum;pkt2give.acknum = eventptr->pktptr->acknum;pkt2give.checksum = eventptr->pktptr->checksum;for (i=0; i<20; i++)pkt2give.payload[i] = eventptr->pktptr->payload[i];if (eventptr->eventity == A) /* deliver packet by calling */ A_input(pkt2give); /* appropriate entity */elseB_input(pkt2give);free(eventptr->pktptr); /* free the memory for packet */ }else if (eventptr->evtype == TIMER_INTERRUPT){if (eventptr->eventity == A)A_timerinterrupt();elseB_timerinterrupt();}else{printf("INTERNAL PANIC: unknown event type \n");}free(eventptr);}terminate:printf(" Simulator terminated at time %f\n after sending %d msgs from layer5\n",time,nsim);printf(" correctly sent pkts: %d \n", packet_correct);printf(" resent pkts: %d \n", packet_resent);system("pause");}附源代码及注释四. 实验小结通过本次试验了解了编程实现简单可靠的数据传输GBN协议,模拟了可靠数据传输理解了TCP协议可靠传输的差错检测、重传、累计确认、定时器的可靠传输策略。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
云南大学软件学院实验报告
序号:01 实验老师:代飞实验时间:2011/10/17 姓名:袁秀梅
实验名称: COBOL程序的编译与运行学号:20091120107
一、实验原理
1、大型机数据集的建立
2、COBOL源程序的设计与输入大型机
3、JCL程序的设计与输入大型机
4、编译程序
5、以不同方式运行程序
二、实验目的
1. 熟悉PCOM及ISPF环境;
2. 熟悉在大机系统编译连接与运行基本COBOL程序的方法;
3. 掌握基本是输入输出语句的使用。
三、实验内容
1、连接主机
安装PCOMM软件,点击通信菜单中的配置选项,如图1所示;在定制通信图像界面中,如图2所示,点击链路参数,配置服务器地址:202.115.7.252,端口23,如图3所示;点击会话参数,在主机代码选项中,选择037 美国。
2、在配置完上述基本设置后,进入登录界面,如图5所示,输入TSO,回车(键盘上的CTRL键),进入如图6所示的屏幕,输入自己的用户名。
3、修改密码
4、成功登录后应该会看到TSO 的主屏,输入ISPF,进入如图8所示界面。
5、创建数据集
在TSO主屏,如图9所示,在红色方框处输入3.2(也可以依次输入3、2)回车(键盘的右CTRL键)。
6、接下来会进入数据集工具屏,如图10所示,要求输入数据集名称和所在卷标,创建数据集YNTE03.COBOL.SOURCE。
注意:YNTE03是我的账号。
如法炮制,使用相同的流程和参数创建数据集YNTE03.COBOL.JCL,其作用存放编译COBOL程序和运行结果程序的JCL程序。
最后,创建存放编译结果的数据集YNTE03.COBOL.LOAD,图11是数据集的参数配置图,注意其记录格式为U。
3、设计并输入COBOL源程序
在Option处输入4,回车(键盘的右CTRL键),进入数据集查看界面,如图13所示。
图在Option处输入回车,进入如图14所示,并在YNTE03.COBOL.SOURCE中建立一
个TEST1的MEMBER,如图中红色方框所示输入,完毕后回车。
图5 选择应用程序终端
图6 输入用户名
在接下来的屏幕中按提示输入自己的口令,如图7。
如果是第一次登陆,必须修改密码。
(1)首先使用由老师分配的IBM的主机用户名和密码登陆大型机
(2)建立相应数据集
● 建立用于存放COBOL源程序的分区数据集
● 建立用于存放JCL程序的分区数据集
● 再根据建立存放编译结果的数据集
(3)设计并输入COBOL源程序
(4)输入编译JCL程序,并编译源程序为目标文件
(5)输入运行的JCL程序,并运行编译结果
(6)控制台方式运行编译程序。