程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> c++ 結構體練習 結構體重的char數組指針

c++ 結構體練習 結構體重的char數組指針

編輯:C++入門知識

[cpp]
#include<iostream>  
#include<string>  
using namespace std; 
class zxl{ 
public: 
    struct z{ 
    int num; 
    char *name; 
    char sex; 
    int age; 
    float score; 
    char *addr; 
    }z_1; 
    void zxl_1(); 
}; 
void zxl::zxl_1(){ 
    cout<<z_1.num<<"  "<<z_1.name<<"  "<<z_1.sex<<"  "<<z_1.age<<"  "<<z_1.score<<"  "<<z_1.addr<<"  "<<endl; 

 
int main(){ 
zxl zx; 
cout<<"啟始數據"<<endl; 
zx.z_1.num=1001; 
zx.z_1.name="zxl"; 
zx.z_1.sex='n'; 
zx.z_1.age=21; 
zx.z_1.score=111; 
zx.z_1.addr="helloworld"; 
zx.zxl_1(); 
cout<<"手動輸入數據數據"<<endl; 
cout<<"num:"<<endl; 
cin>>zx.z_1.num; 
cout<<"name:"<<endl; 
char array[20]; 
zx.z_1.name=array; 
cin>>zx.z_1.name; 
cout<<"sex:"<<endl; 
cin>>zx.z_1.sex; 
cout<<"age:"<<endl; 
cin>>zx.z_1.age; 
cout<<"score:"<<endl; 
cin>>zx.z_1.score; 
cout<<"addr:"<<endl; 
char array1[20]; 
zx.z_1.addr=array1; 
cin>>zx.z_1.addr; 
 
zx.zxl_1(); 
 
system("pause"); 
    return 0; 

#include<iostream>
#include<string>
using namespace std;
class zxl{
public:
 struct z{
 int num;
 char *name;
 char sex;
 int age;
 float score;
 char *addr;
 }z_1;
 void zxl_1();
};
void zxl::zxl_1(){
 cout<<z_1.num<<"  "<<z_1.name<<"  "<<z_1.sex<<"  "<<z_1.age<<"  "<<z_1.score<<"  "<<z_1.addr<<"  "<<endl;
}

int main(){
zxl zx;
cout<<"啟始數據"<<endl;
zx.z_1.num=1001;
zx.z_1.name="zxl";
zx.z_1.sex='n';
zx.z_1.age=21;
zx.z_1.score=111;
zx.z_1.addr="helloworld";
zx.zxl_1();
cout<<"手動輸入數據數據"<<endl;
cout<<"num:"<<endl;
cin>>zx.z_1.num;
cout<<"name:"<<endl;
char array[20];
zx.z_1.name=array;
cin>>zx.z_1.name;
cout<<"sex:"<<endl;
cin>>zx.z_1.sex;
cout<<"age:"<<endl;
cin>>zx.z_1.age;
cout<<"score:"<<endl;
cin>>zx.z_1.score;
cout<<"addr:"<<endl;
char array1[20];
zx.z_1.addr=array1;
cin>>zx.z_1.addr;

zx.zxl_1();

system("pause");
 return 0;
}

 

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved