找回密码
 中文实名注册
查看: 257|回复: 2

李松沐 实验中学 七(一)班

[复制链接]

15

主题

96

帖子

2131

积分

金牌会员

Rank: 6Rank: 6

积分
2131
发表于 2022-9-18 15:30:56 | 显示全部楼层 |阅读模式
C++课程作业
回复

使用道具 举报

15

主题

96

帖子

2131

积分

金牌会员

Rank: 6Rank: 6

积分
2131
 楼主| 发表于 2022-9-18 15:32:07 | 显示全部楼层

C++程序设计

本帖最后由 李松沐 于 2022-9-18 15:33 编辑

[C++] 纯文本查看 复制代码
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
        cout<< "Hello,World!"<< endl;
        cout<< fixed<<setprecision(2)<<(1+3)*(3+4)<<endl;
        cout<<fixed<<setprecision(2)<< 3+4-9<<endl;
        cout<< fixed<<setprecision(2)<<50/100<< endl;
        cout<< fixed<<setprecision(2)<<4/3*3.14*4*4*4<< endl;
        cout<< fixed<<setprecision(2)<<3.1415926<< endl;
        cout<< fixed<<setprecision(2)<<(96.0+93+98)/3<< endl;
        return 0;
}
回复

使用道具 举报

15

主题

96

帖子

2131

积分

金牌会员

Rank: 6Rank: 6

积分
2131
 楼主| 发表于 2023-10-15 19:26:28 | 显示全部楼层
[C++] 纯文本查看 复制代码
#include<iostream>
using namespace std;
#define MaxVnum 100
bool visited[MaxVnum];
typedef char VexType;
typedef int EdgeType;
typedef struct{
	Vextype Vex[MaxVnum];
	EdgeType Edge[MaxVnum][MaxVnum];
	int vexnum,edgenum;
}AMGragh;
int locatevex(AMGragh G,VexType x) {
	for (int i=0;i<G.vexnum;i++){
		if (x==G.Vex[i])
			return i;
		return -1;
			
	}
}
void CreateAMGragh(AMGragh& G){
	int i,j;
	VexType u,v;
	cout<<"请输入定点数"<<endl;
	cin>>G.vexnum;
	cout<<"请输入边数"<<endl;
	cin>>G.edgenum;
	cout<<"请输入定点信息"<<endl;
	for (int i=0;i<G.vexnum;i++){
		cin>>G.Vex[i];
		
	}
	for (int i=0;i<G.vexnum;i++){
		for (int j=0;j<G.vexnum;j++){
			G.Edge[i][j]=0;
			
		}
	}
	cout<<"请输入每条边依附的两个顶点"<<endl;
	while(G.edgenum--){
		cin>>u>>v;
		i=locatevex(G,u);
		j=locatevex(G,v);
		if (i!=-1&&j!=1){
			G.Edge[i][j]==G.Edge[j][i]=1;
			
		}else{
			cout<<"输入顶点信息错!请重新输入"<<endl;
			G,edgenum++;
		}
	}	
}
void print(AMGragh &G){
	cout<<"图的邻接矩阵为"<<endl;
	for (int i=0;j<G.vexnum;i++){
		for (int j=0;j<G.vexnum;j++){
			cout<<G.Edge[i][j]<<"\t";
		cout<<endl;
		}
		
	}
}
int main (){
	int v;
	VexType c;
	AMGragh G;
	CreateAMGragh(G);
	print(G)
	
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 中文实名注册

本版积分规则

小黑屋|东台市机器人学会 ( 苏ICP备2021035350号-1;苏ICP备2021035350号-2;苏ICP备2021035350号-3 )

GMT+8, 2024-4-25 18:36 , Processed in 0.044511 second(s), 26 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表