高级语言程序设计
课 程 实 验 报 告
专 业: 软件工程
年 级: 17级
姓 名: **
学 号: 201742060220
教 师: ***
日 期: 2018101
** 民 族 学
目录
实验目 3
二 务求 3
三 标识符数结构 4
四 问题分析算法设计 6
五 程序运行测试实例 11
六 问题总结 15
附录(源代码) 15
实验目
1 掌握新学线性表操作
2 加深书写代码流畅度
二 务求
1 问题描述
l 题目1:设计种单链表存储项式结构(结点存储项系数指数类型int)编写产生项式链表函数实现两项式相加相函数
l 题目2:试章介绍两种josephus问题求解程计算机中实现实现时求输出整数实际名
l 题目3:
2 设计达求
l 正确输出题目求结果
l 正确线性表
三 标识符数结构
说明:1描述清楚标识符 格式
标识符
数类型
含义
第题
ptrNode
struct node
typedef 转换
Coefficient Exponent
int
指数系数
headrp
LinkList
生成结点遍历链表函数(LinkList creatList(int n))
ha hb
Position
函数LinkList add_List(LinkList a LinkList b)完成项式相加操作
crp
LinkList
函数LinkList add_List(LinkList a LinkList b)完成项式相加操作
ha hb
Position
函数LinkList mul_List(LinkList a LinkList b)完成项式相
ctempCrp
LinkList
函数LinkList mul_List(LinkList a LinkList b)完成项式相
hc
LinkList
函数void printList(LinkList L)遍历链表进行输出链表操作
n1n2
int
函数中需输入项式项数
L1L2L3L4
LinkList
函数中接受调函数返回值
第二题
标识符
数类型
含义
DataType
struct Person
结构体数类型
typedef struct Node* PNode
LinkList
struct Node
结构体数类型
typedef struct Node* LinkList
PLinkList
LinkList
typedef LinkList* PLinkList
pq
PNode
PNode类型指针函数int init_clist(PLinkList pclist int n)
p pre
PNode
PNode类型指针函数void josephus_clist(PLinkList pclist int s int m)
xyz
int
循环表总数x第y开始数第z 出局
josephus
LinkList
LinkList类型指针函数中
第三题
标识符
数类型
含义
Plist
Data
struct List
结构体数类型
numbername
Char
存放电话号存放姓名
next
struct List
struct List指针变量
Plist
data
delpt
pList
中间变量
count
int
作计算数
四 问题分析算法设计
1 问题分析
说明:分析程序题目求详细说明程序设计思想
2 算法设计
l 第题
S1:定义struct node{
ElementType Coefficient
ElementType Exponent
Position next
}
S2:typedef struct node *ptrNode
typedef ptrNode LinkList 头结点
typedef ptrNode Position中间节点
typedef int ElementType
S3:写函数int IsEmpty(LinkList L)判断参数LinkList L空
S4: 写函数LinkList add_List(LinkList a LinkList b)进行项式加法计算
S5:写函数LinkList mul_List(LinkList a LinkList b)进行项式法计算
S6: 函数中调函数输出加法结果法结果
处出进行加法LinkList add_List(LinkList a LinkList b)函数算法:
S1:函数形参LinkList a LinkList b定义Position ha hbLinkList crp int temp
S2:ha a>next hb b>next
S3:分配存储空间C然r c
S4:然循坏while((ha NULL)&&(hb NULL))分配存储空间p
S5:if(ha>Exponent < hb>Exponent)条件p>Exponent hb>Exponent p>Coefficient hb>Coefficient hb hb>next r>next p r p
S6:else if(ha>Exponent > hb>Exponent) 条件p>Exponent ha>Exponent p>Coefficient ha>Coefficient ha ha>next r p
S7:else 条件{
temp ha>Coefficient + hb>Coefficient
if(temp 0){
p>Exponent ha>Exponent
p>Coefficient temp
r>next p
r p }
hb hb>next
ha ha>next } }
S8:操作完成if(hb NULL)进行while(ha NULL){
p (struct node*)malloc(sizeof(struct node))
p>Exponent ha>Exponent
p>Coefficient ha>Coefficient
ha ha>next
r>next p
r p
}
S9:if(hb NULL)进行while(ha NULL){
p (struct node*)malloc(sizeof(struct node))
p>Exponent ha>Exponent
p>Coefficient ha>Coefficient
ha ha>next
r>next p
r p
}
S10:r>next NULL
S11:返回值return c
l 第二题
S1: 定义struct Person结构体{ int num char name[8] } typedef struct Person DataType词结构体存储 元素
S2:创建struct Nodetypedef struct Node* PNode结点类型
S3:struct Node{ DataType info PNode link } typedef struct Node* LinkListtypedef LinkList* PLinkList
S4: 写函数int init_clist(PLinkList pclist int n) 进行循环表初始化
S5:写函数void josephus_clist(PLinkList pclist int s int m) 进行循环表操作
S6:函数中 LinkList josephus写三循坏分循环表总数x第y开始数第z 出局三函数
do{printf(\t循环表总数x )scanf(d&x) }while(x<1)
do{printf(\t第y开始数 )scanf(d&y) }while(y<1)
do{printf(\t第z 出局 )scanf(d&z) }while(z<1)
S7:然写判断if (init_clist(&josephusx)) josephus_clist(&josephusyz)
else printf(溢出\n)
S8:return 0
S9:结束
l 第三题:
S1:定义结构体struct List{char number[20] char name[20] struct List* next }
S2:typedef struct List* PList typedef struct List Data
S3: 写增加空链表函数PList createNullList()
S4:写增加号码函数int addNewPre(PList plistData x)
S5:写删号码函数int delPosX(PList plistchar *name)
S6:写查号码函数int lookAll(PList plist)
S7:写查找号码函数 int findData(PList plistchar *name)
S8:函数中定义PList p 接收createNullList()中返回值
写菜单然菜单中调增删查查找4函数
S9:return 0
S10:结束
五 程序运行测试实例
l 第题图
图例11
l 第题图二
图例12
l 第题图三
图例13
l 第二题图1
图例21
l 第二题图2
图例22
l 第二题图3
图例23
l 第三题图:
图例31
l 第三题图二:
图例32
六 问题总结
说明:提出程序设计中需进步深入考虑问题总结整设计取结果做简单分析总结设计程中心体会求实事求出现空话套话
l 第2题序表模拟输出josephus问题点问题没调试出没写实验报告写采循坏链表模拟
l 第3题点bug
附录(源代码)
明:粘贴设计程序源代码
第源代码:
#include
#include
typedef struct node *ptrNode
typedef ptrNode LinkList 头结点
typedef ptrNode Position中间节点
typedef int ElementType
struct node{
ElementType Coefficient
ElementType Exponent
Position next
}
int IsEmpty(LinkList L)
{
return L>next NULL
}
LinkList creatList(int n)
{
LinkList headrp
int coeexp
head (struct node*)malloc(sizeof(struct node)) 生成新结点
r head
while(n){
scanf(dd&coe&exp)
p (struct node*)malloc(sizeof(struct node))
p>Coefficient coe
p>Exponent exp
r>next p
r p
}
r>next NULL
return head
}
LinkList add_List(LinkList a LinkList b)
{ Position ha hb
LinkList crp
int temp
ha a>next
hb b>next
c (struct node*)malloc(sizeof(struct node))
r c
while((ha NULL)&&(hb NULL)){
p (struct node*)malloc(sizeof(struct node))
if(ha>Exponent < hb>Exponent){
p>Exponent hb>Exponent
p>Coefficient hb>Coefficient
hb hb>next
r>next p
r p
}
else if(ha>Exponent > hb>Exponent){
p>Exponent ha>Exponent
p>Coefficient ha>Coefficient
ha ha>next
r>next p
r p
}
else{
temp ha>Coefficient + hb>Coefficient
if(temp 0){
p>Exponent ha>Exponent
p>Coefficient temp
r>next p
r p
}
hb hb>next
ha ha>next
}
}
if(ha NULL){
while(hb NULL){
p (struct node*)malloc(sizeof(struct node))
p>Exponent hb>Exponent
p>Coefficient hb>Coefficient
hb hb>next
r>next p
r p
}
}
if(hb NULL){
while(ha NULL){
p (struct node*)malloc(sizeof(struct node))
p>Exponent ha>Exponent
p>Coefficient ha>Coefficient
ha ha>next
r>next p
r p
}
}
r>next NULL
return c
}
LinkList mul_List(LinkList a LinkList b)
{
Position ha hb
LinkList ctempCrp
ha a>next
hb b>next
c (struct node*)malloc(sizeof(struct node))
c>next NULL
c creatList(0)
if(ha NULL || hb NULL){
return c
}
while(ha NULL ){
tempC (struct node*)malloc(sizeof(struct node))
r tempC
hb b>next
while(hb NULL){
p (struct node*)malloc(sizeof(struct node))
p>Exponent ha>Exponent + hb>Exponent
p>Coefficient ha>Coefficient*hb>Coefficient
hb hb>next
r>next p
r p
}
r>next NULL
c add_List(ctempC)
tempHead tempC>next
tempC>next NULL
while(tempHead NULL){
free(tempHead)
tempHead tempHead>next
}
ha ha>next
}
return c
}
void printList(LinkList L)
{
LinkList hc
int flag 0
hc L>next
if(hc NULL)
printf(0 0)
while(hc NULL){
if(flag)
printf( )
else
flag 1
printf(d dhc>Coefficienthc>Exponent)
hc hc>next
}
}
int main(void)
{
int n1n2
LinkList L1L2L3L4
printf(第项式需输入项:\n)
scanf(d&n1)
printf(请输入d项项式:\nn1)
L1 creatList(n1)
printf(第二项式需输入项\n)
scanf(d&n2)
printf(请输入d项项式:\nn2)
L2 creatList(n2)
L3 add_List(L1L2)
L4 mul_List(L1L2)
printf(加法结果(两数字间分系数指数):\n)
printList(L3)
printf(\n)
printf(法结果(两数字间分系数指数):\n)
printList(L4)
system(pause)
return 0}
l 第二题源代码
#include
#include
#include
#define Fal 0
#define True 1
struct Person元素类型
{
int num
char name[8]
}
typedef struct Person DataType
结点类型
struct Node
typedef struct Node* PNode
struct Node
{
DataType info
PNode link
}
typedef struct Node* LinkList
typedef LinkList* PLinkList
int init_clist(PLinkList pclist int n)循环表初始化
{
PNode pq
int ijcpy_icount0
char temp[10]
q (PNode)malloc(sizeof(struct Node))
if (q NULL) return Fal
*pclist q
(q>info)num1
strcpy((q>info)name1)
q>link q
if (n 1) return True
初始化(n)结点循环表
for (i2 i
p (PNode)malloc(sizeof(struct Node))
if (p NULL) return Fal
(p>info)num i
memset((p>info)name'\0'sizeof(char)*8)
strcpy((p>info)name)
cpy_i i
memset(temp'\0'sizeof(char)*10)
j0count0
while (cpy_i 0)
{
temp[j] cpy_i10 + '0'
cpy_i 10
j++
count++
}
j0
while (countj>0)
{
char otemp[j]
temp[j] temp[count1]
temp[count1] o
j++
count
}
char* th &(p>info)name[2]
strcpy(thtemp)
p>link q>link
q>link p
q p
}
return True
}
循环表操作
void josephus_clist(PLinkList pclist int s int m)
{
PNode p pre
int i
p *pclist
找第s元素
if (s1)
{
pre p
p p>link
while (p*pclist)
{
pre p
p p>link
}
}
else
for (i1 i
pre p
p p>link
}
while (pp>link)
{
for(i1i
pre p
p p>link
}
printf(出局 s\n(p>info)name)
if (*pclistp)
*pclist p>link
pre>link p>link
free(p)
p pre>link
}
printf(终剩 s\n(p>info)name)
*pclist NULL
free(p)
}
int main()
{
LinkList josephus
int xyz
do{
printf(\t循环表总数x )
scanf(d&x)
}while(x<1)
do{
printf(\t第y开始数 )
scanf(d&y)
}while(y<1)
do{
printf(\t第z 出局 )
scanf(d&z)
}while(z<1)
if (init_clist(&josephusx))
josephus_clist(&josephusyz)
else
printf(溢出\n)
getchar()
system(pause)
return 0
}
l 第三源代码
#include
#include
#include
struct List
{
char number[20]
char name[20]
struct List* next
}
typedef struct List* PList
typedef struct List Data
PList createNullList()增加空链表
{
PList plist (PList)malloc(sizeof(struct List))
if (plistNULL)
{
printf(Building false\n)
return NULL
}
else 初始化
{
memset(&plist>number'\0'sizeof(plist>number))
memset(&plist>name'\0'sizeof(plist>name))
plist>next NULL
}
return plist
}
int addNewPre(PList plistData x)增加
{
PList data (PList)malloc(sizeof(PList))
PList t plist
if (t>next NULL)
while (true)
{
if (strcmp(t>next>namexname)0)
t t>next
else if (t>next NULL)
break
else
{
printf(输入重复\n)
return 1
}
}
strcpy(data>numberxnumber)
strcpy(data>namexname)
data>next plist>next
plist>next data
printf(增加成功(ss)\ndata>namedata>number)
return 0
}
int delPosX(PList plistchar *name)删
{
PList del
PList t plist
查找位置
while (strcmp(t>next>namename)0)
t t>next
del t>next
t>next t>next>next
printf(Delete success(s)\ndel>number)
free(del)
return 0
}
int lookAll(PList plist)查
{
int i1
PList t plist>next
if (plist>nextNULL)
{
printf(空\n)
return 0
}
else
{
while(t>nextNULL)
{
int
printf(ds s\ni++t>namet>number)
t t>next
}
printf(ds s\nit>namet>number)
}
return 0
}
int findData(PList plistchar *name)查找输出
{
int count0
PList t plist
printf(查找结果\n)
while (tNULL)
{
if (strcmp(t>namename)0)
{
printf(s s\nt>namet>number)
t t>next
count++
}
else
t t>next
}
if (count 0)
{
printf(d位联系\ncount)
return 0
}
else
printf(未找(s)信息\nname)
return 1
}
int main()
{
PList p createNullList()
Data t
char ch1
while (ch '0')
{
printf(\t 通讯录\t\n)
printf(\n)
printf(\t1查联系\n)
printf(\t2新建\n)
printf(\t3删\n)
printf(\t4查找\n)
printf(\n )
ch getchar()
switch(ch)
{
case '1'
lookAll(p)
break
case '2'
printf(name )
scanf(s&tname)
printf(number )
scanf(s&tnumber)
addNewPre(pt)
break
case '3'
printf(name )
scanf(s&tname)
delPosX(ptname)
break
case '4'
printf(name )
scanf(s&tname)
findData(ptname)
break
defaultbreak
}
getchar()
if (ch'0')
break
else
system(pause)
}
return 0
}
总体格式求:标题求宋体三号加粗两倍行距段前05行段05行正文求宋体四15倍行距段前05行流程图求居中实验结果图求居中图例图11 实验结果图图例求位实验结果图正方程序代码求宋体五号15倍行距段前段均0行代码必代码解释
文档香网(httpswwwxiangdangnet)户传
《香当网》用户分享的内容,不代表《香当网》观点或立场,请自行判断内容的真实性和可靠性!
该内容是文档的文本内容,更好的格式请下载文档