C++类数组的实现
2024-10-18 02:11:28
请看下面的代码:
//xy_3_1 2013/10/26
#include<stdio.h>
#include<iostream.h>
#include<string.h> class Student{
public:
Student(){};
Student(Student &p);
int no;
char name[];
float score1;
float score2;
float score3;
void input();
void display();
void display1(); private:
Student *ptr; }; Student::Student(Student &p){ //construct memeber;
ptr=&p; } void Student::input(){
Student *w;
w=ptr;
cout<<"请输入学生 姓名 学号 成绩1 成绩2 成绩3"<<endl;
for(int i=;i<;i++){
cin>>w->name>>w->no>>w->score1>>w->score2>>w->score3;
w++;
}
} void Student::display(){
Student *w;
w=ptr;
cout<<"输出数据:"<<endl;
cout<<"姓名"<<'\t'<<"学号"<<'\t'<<"成绩1"<<'\t'<<"成绩2"<<'\t'<<"成绩3"<<endl;
for(int i=;i<;i++){
cout<<w->name<<'\t'<<w->no<<'\t'<<w->score1<<'\t'<<w->score2<<'\t'<<w->score3<<endl;
w++;
}
}
int main()
{ Student *a=new Student[];
a->input();
a->display();
return ;
}
我想实现 类数组的一个传递接口 实现的代码如上面的那样 但是我却不知道如何把数组的下标给传递进类的接口中 从而实现封装 正如上面的输入和输出的循环数组中的 3 ,我本来想在main中吧这个 3 给传递进构造函数中的 但我却不知道应该如何实现 如果有位好心人 路过 看到 请不吝赐教 小子感激不尽。
最新文章
- 使用Json Web Token设计Passport系统
- iOS9 适配(杂七杂八)
- error: could not read CFBundleIdentifier from Info.plist (null)解决方法之一
- linux权限补充:rwt rwT rws rwS 特殊权限
- JAVA对文件类型的校验
- IOS开发中与设计沟通之字体大小转换
- libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated with hostname)
- andriod GridView
- 常用的math函数
- 不加班的实践(1)——这真的该用try-catch吗?
- StringBuilder是不是线程安全的?
- 苹果试图做?XCode6 放弃prefix.pch档
- 阿里云CentOS搭建系统
- iOS 轻松实现自定义TabBar
- OO第四次博客作业
- word中插入myth type公式行距变大的问题
- Jexus~mono中使用StackExchange.redis的问题
- 在grails中远程调用action
- JavaScript 之 JavaScript 对象
- TCP连接建立与释放
热门文章
- 2018-2019-2 20165219《网络对抗技术》Exp4 恶意代码分析
- 【OCP-12c】CUUG 071题库考试原题及答案解析(15)
- Spring 中aop切面注解实现
- sonarLint和sonarQube
- robot framework-接口测试实例一
- java学习笔记_接口
- Linux之E: 无法锁定管理目录(/var/lib/dpkg/),是否有其他进程正占用它?
- P5242 [USACO19FEB]Cow Dating
- UVALive-7457-Discrete Logarithm Problem(取模运算)
- 对drf视图的理解