指標與陣列.ppt

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
指標與陣列

* //Program: Example with 2 structure pointers in a function #include iostream.h #include string.h struct Bird { char species[25]; int count; char location[25]; }; struct B_Watcher { char name[50]; int qualification_code; }; void WatchTheBirdie(Bird *, B_Watcher *); //prototypes void WhatDidYouSee(Bird *, B_Watcher *); int main() { Bird birdie; B_Watcher person; cout \n Watch the Birdie Program \n; WatchTheBirdie(birdie, person); //call sends addresses of structs WhatDidYouSee(birdie, person); return 0; } void WatchTheBirdie(Bird *B_ptr, B_Watcher *BW_ptr) { strcpy( B_ptr-species,sparrow hawk); B_ptr-count = 3; strcpy( B_ptr-location,Sandia Mountains); strcpy(BW_ptr-name,Ryan Andrew); BW_ptr-qualification_code = 5; } void WhatDidYouSee(Bird *B_ptr, B_Watcher *BW_ptr) { cout \n Watcher: BW_ptr-name; cout \n Qualification: BW_ptr-qualification_code; cout \n Species: B_ptr-species; cout \n Count: B_ptr-count endl; } * * Structure Arrays and Functions The function accesses the structure array elements using the normal array operator [] * //Program: Structure Array of Student data to a function #include iostream.h #include string.h struct Student { char name[40]; char ID_Num[15]; int dept; float gpa; }; void GetStudentInfo(Student []); //prototype, sending array of Student data type void main() { Student MyStudents[100]; GetStudentInfo(MyStudents);//MyStudents is a pointer to MyStudents[] array } void GetStudentInfo(Student x[]) //temp_ptr is pointer with address { strcpy(x[0].name, “Melissa”); strcpy(x[0].ID_Num, “123-45-6789”); x[0].dept = 2; x[0].gpa = 3.6; strcpy(x[1].name, “Sue”); strcpy(x[1].ID_Num, “987-65-4321”); x[1].dept = 1; x[1].gpa = 3.7; } * Illustrating Program 7-9 * Enumerated Data Types enum creates numbered lists Enumerated data type: user –defined data types

文档评论(0)

book1986 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档