当前位置: 首页 > news >正文

做网购内部优惠券网站网络推广和信息流优化一样么

做网购内部优惠券网站,网络推广和信息流优化一样么,什么软件免费设计logo,网站做的好不好数据结构体 //一、结构体的概念、定义和使用 // 概念&#xff1a;结构体属于用户自定义的数据类型&#xff0c;允许用户存储不同的数据类型 #include<iostream> using namespace std; #include<string> //1.创建学生数据类型&#xff1a;学生包括&#xff08;姓名&am…

结构体

//一、结构体的概念、定义和使用


// 概念:结构体属于用户自定义的数据类型,允许用户存储不同的数据类型

#include<iostream>
using namespace std;
#include<string>
//1.创建学生数据类型:学生包括(姓名,年龄,分数)
//自定义数据类型,一些类型集合组成的一个类型
//语法 strcut 类型名称{成员列表};  注意后面有;
struct Student
{//成员列表//姓名string name;//年龄int age;//分数int score;
}s3;//2.通过学生类型创建具体学生int main()
{
//2.1 struct Student s1//strcut关键字可以省略//struct Student s1;Student s1;//给s1属性赋值,通过.访问结构体变量中的属性s1.name = "张三";s1.age = 18;s1.score = 100;cout << "姓名:" << s1.name << " 年龄:" << s1.age << " 分数:" << s1.score << endl;
//2.2 struct Student s2={...}struct Student s2 = { "李四",19,80 };cout << "姓名:" << s2.name << " 年龄:" << s2.age << " 分数:" << s2.score << endl;//2.3 在定义结构体时顺便创建结构体变量(如果没有s3,则上面数据{}后要加;s3.name = "王五";s3.age = 20;s3.score = 60;cout << "姓名:" << s3.name << " 年龄:" << s3.age << " 分数:" << s3.score << endl;//一般用第1或2种return 0;
}

//二、结构体数组


//作用:将自定义的结构体放入到数组中方便维护
//语法:struct 结构体名 数组名{元素个数}={ {},{},...{} }

#include<iostream>
using namespace std;//结构体数组
//1.定义结构体
struct Student
{string name;int age;int score;
};
int main()
{//2.创建结构体数组struct Student stuArray[3] ={{"张三",18,100},{"李四",28,99},{"王五",38,66}};//3.给结构体数组中的元素赋值//一开始不知道人家名字,后面改stuArray[2].name = "赵六";stuArray[2].age = 80;stuArray[2].score = 80;//4.便利结构体数组for (int i = 0; i < 3; i++){cout    << " 姓名: " << stuArray[i].name << " 年龄: " << stuArray[i].age << " 分数: " << stuArray[i].score << endl;}return 0;
}

//三、结构体指针


//作用:通过指针访问结构体中的成员 利用操作符->

#include<iostream>
using namespace std;struct student
{string name;int age;int scroe;
};
int main()
{//1.创建学生结构体变量struct student s = { "张三",18,100 };//struct可省略//2.通过指针指向结构体变量struct student* p = &s;//struct可省略//3.通过指针访问结构体变量中的数据//通过结构体指针 访问结构体中的属性,需要利用'->'cout << "姓名: " << p->name << " 年龄: " << p->age << " 分数: " << p->scroe << endl;return 0;
}

//四、结构体嵌套结构体


//作用:结构体中的成员可以是另一个结构体

#include<iostream>
using namespace std;
#include<string>struct student
{string name;int age;int score;
};
struct teacher
{int id;string name;int age;struct student s;
};int main()
{teacher t;t.id = 18888;t.name = "老王";t.age = 50;t.s.name = "小王";t.s.age = 20;t.s.score = 60;cout << "老师姓名: " << t.name << " 老师编号: " << t.id << " 老师年龄: " << t.age<< " 老师辅导学生姓名:  " << t.s.name << " 学生年龄: " << t.s.age << "  学生分数: " << t.s.score << endl;return 0;
}

//五、结构体做函数参数


//作用:将结构体作为参数向函数中传递
//传递方式有两种:值传递和地址传递

#include<iostream>
using namespace std;
#include<string>struct student
{string name;int age;int score;
};
//打印学生信息函数
//1.值传递
void printStudent1(struct student s)
{s.age = 100;cout << " 子函数1中 姓名:" << s.name << " 年龄:" << s.age << " 分数: " << s.score << endl;
}
//2.地址传递
void printStudent2(struct student * p)
{p->age = 200;cout << "子函数2中 姓名:" << p->name << " 年龄: " << p->age << " 分数: " << p->score << endl;
}
int main()
{//结构题做函数参数//将学生传入到一个参数中,打印学生身上的所有信息//创建一个结构体变量struct student s;s.name = "张三";s.age = 18;s.score = 85;printStudent1(s);printStudent2(&s);cout << "main函数中打印 姓名:" << s.name << " 年龄: " << s.age << " 分数:" << s.score<<endl;return 0;
}

//六、结构体中const使用场景


//作用:用const来防止误操作

#include<iostream>
using namespace std;
#include<string>//const的使用场景struct student
{string name;int age;int score;
};//将函数中的形参改为指针,可以减少内存空间,而且不会复制新的副本出来
void printStudent(const student *s)//指针目的是节省空间,const是防止修改了形参把实参变了,即防止误操作
{s->age = 150;//(误操作了)//但是利用了const age还是为15岁  只能读不能写cout << "姓名: " << s->name << " 年龄: " << s->age << " 得分: " << s->score << endl;
}int main()
{//创建结构体变量struct student s = { "张三",15,70 };//通过函数打印结构变量信息printStudent(&s);cout << s.age;return 0;
}

http://www.fp688.cn/news/156751.html

相关文章:

  • 淘宝客如何免费做网站郑州网站推广公司
  • 网站页脚优化怎么做石家庄网站建设方案
  • 泰州城乡建设网站网络推广平台公司
  • 做威尼斯网站代理算是违法吗seo诊断的网络问题
  • 公司注册流程及条件seo快速工具
  • 什么类型客户做网站全网关键词搜索
  • 网站建设需要下载哪些软件有哪些网站建设公司排行榜
  • 怎样上传网站电商自学网
  • 福州网站建设要找嘉艺网络排行榜软件
  • 网站建设网站建设的网络公司100个成功营销案例
  • 程序员自学网站湖南 seo
  • 摄影网站的设计与实现开题报告seo入门教程网盘
  • 用vue做多页面网站电商代运营
  • 永年做网站多少钱网站关键字排名优化
  • 如何给网站做排名优化网络广告的计费方式
  • 智能管理系统定制开发seo策略主要包括
  • 山东网站建设公司哪家专业广州白云区新闻头条最新消息今天
  • 宣传片制作的十大步骤北京网站优化指导
  • wordpress o2o插件seo技术培训东莞
  • 人是用什么做的视频网站吗广告投放
  • WordPress仿虎嗅主题seo站长综合查询工具
  • 网站建设进度表求几个微信推广平台
  • 织梦 网站版权信息西安网站seo技术
  • 小程序制作的相册如何存入图库搜索关键词优化排名
  • 做本地的分类信息网站个人网页制作成品欣赏
  • 网站怎么设计制作企业网站建设原则是
  • wordpress 5.1.1seo整站优化技术培训
  • 聊城哪有做网站的关键词一般是指什么
  • html设计主题网站代码海淀seo搜索优化多少钱
  • 即墨做网站的seo待遇