李松沐 发表于 2022-9-18 15:30:56

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

C++课程作业

李松沐 发表于 2022-9-18 15:32:07

C++程序设计

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

#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;
}

李松沐 发表于 2023-10-15 19:26:28

#include<iostream>
using namespace std;
#define MaxVnum 100
bool visited;
typedef char VexType;
typedef int EdgeType;
typedef struct{
        Vextype Vex;
        EdgeType Edge;
        int vexnum,edgenum;
}AMGragh;
int locatevex(AMGragh G,VexType x) {
        for (int i=0;i<G.vexnum;i++){
                if (x==G.Vex)
                        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;
               
        }
        for (int i=0;i<G.vexnum;i++){
                for (int j=0;j<G.vexnum;j++){
                        G.Edge=0;
                       
                }
        }
        cout<<"请输入每条边依附的两个顶点"<<endl;
        while(G.edgenum--){
                cin>>u>>v;
                i=locatevex(G,u);
                j=locatevex(G,v);
                if (i!=-1&&j!=1){
                        G.Edge==G.Edge=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<<"\t";
                cout<<endl;
                }
               
        }
}
int main (){
        int v;
        VexType c;
        AMGragh G;
        CreateAMGragh(G);
        print(G)
       
}
页: [1]
查看完整版本: 李松沐 实验中学 七(一)班