首页 > 其他分享 >指向对象数组的对象指针

指向对象数组的对象指针

时间:2023-05-22 22:33:19浏览次数:39  
标签:数组 对象 void float int num student display 指针

#include<iostream>
using namespace std;
class student
{
public:
student(int n, float s) :num(n), score(s)
{

}
void display(void);
private:
int num;
float score;
};
void student::display(void)
{
cout << num << ":" << score<<endl;
}
int main()
{
student stu[5] = { student(101,78.5),student(102,85.5),student(103,98.5),student(104,100.0),student(105,95.5) };
student* p = stu;
//student s[1] = { student(101,78.5) };
for (;p<stu+5; p = p + 2)
{
p->display();
}
return 0;
}

标签:数组,对象,void,float,int,num,student,display,指针
From: https://www.cnblogs.com/pinganxile/p/17421946.html

相关文章

  • strtok() 函数_2种方法的指针实现
    //Lvxin4-1strtok.cpp//strtok()函数的实现2种方法//下面的函数实现考虑一下3种极端情况://"-This,asamplestring"无行尾标志//"-This,asamplestring-"有一个行尾标志//"-This,asamplestring------”有多个行尾标志#define_CRT_SECURE_NO_WAR......
  • strtok() 函数 2种方法的指针实现
    //Lvxin4-1strtok.cpp//strtok()函数的实现2种方法//下面的函数实现考虑一下3种极端情况://"-This,asamplestring"无行尾标志//"-This,asamplestring-"有一个行尾标志//"-This,asamplestring------”有多个行尾标志#define_CRT_SECURE_NO_WAR......
  • 编程打卡:面向对象程序设计
    importosimportsqlite3#Createadatabaseconnectionconn=sqlite3.connect('todo.db')#Createatodotablecur=conn.cursor()cur.execute('''CREATETABLEtodo(idINTEGERPRIMARYKEYAUTOINCREMENT,titleTEXTNOTNUL......
  • 数组排序输出(函数模板)
    对于输入的每一批数,按从小到大排序后输出。一行输入为一批数,第一个输入为数据类型(1表示整数,2表示字符型数,3表示有一位小数的浮点数,4表示字符串,0表示输入结束),第二个输入为该批数的数量size(0<size<=10),接下来为size个指定类型的数据。输出将从小到大顺序输出数据。函数接口定义:sor......
  • 找到数组中第几个最小的数据
    找到数组中第几个最小的数据将经典的快速排序算法做简单修改即可示例代码如下:voidtestFindSpecificMin(){intarr[]={2,4,3,9,6,5,7,0,2,1};//intarr[]={4,2,9};//intarr[]={0,1,2,3,4,5,6,7,8};intposition=2;findSpe......
  • strtok() 函数 2种方法的指针实现
    //Lvxin4-1 strtok.cpp //strtok()函数的实现 2种方法//下面的函数实现考虑一下3种极端情况://"-This,asamplestring"无行尾标志//"-This,asamplestring-"有一个行尾标志//"-This,asamplestring------” 有多个行尾标志#define_CRT_SECURE_NO_WARNI......
  • 树状数组学习笔记
    树状数组(BinaryIndexedTree)是一种利用数的二进制特征进行检索的树状结构。树状数组是一种奇妙的数据结构,不仅非常高效,而且代码及其简洁。 #definelowbit(x)((x)&-(x))voidadd(intx,intd){//更新while(x<=n){tree[x]+=d;x+=lowbit(x);}}......
  • strtok() 函数 2种方法的指针实现
    //Lvxin4-1strtok.cpp//strtok()函数的实现2种方法//下面的函数实现考虑一下3种极端情况://"-This,asamplestring"无行尾标志//"-This,asamplestring-"有一个行尾标志//"-This,asamplestring------”有多个行尾标志define_CRT_SECURE_NO_WARNING......
  • 指针和地址变量
    理解指针和地址变量的区别,以及如何正确进行函数传参指针和地址变量的区别:指针是一种变量,它存储的是另一个变量的地址(内存地址)。指针通过存储地址来间接操作某个变量。2.地址变量是存储某个变量地址的普通变量。它直接存储地址这个数值。例如:inta=10;int*p=&a;......
  • Unity自带的对象池——UnityEngine.Pool
    简介之前对象池都是自己写,现在unity的API自带对象池了,UnityEngine.Pool官方文档:https://docs.unity3d.com/ScriptReference/Pool.CollectionPool_2.html主要包含了几个类1.CollectionPool<T0,T1>集合池,可以放List、HashSet、Dictionary啥的,非线程安全2.DictionaryPool<T0,T1>......