1 / 11

C++ Programming: From Problem Analysis to Program Design, Fourth Edition

C++ Programming: From Problem Analysis to Program Design, Fourth Edition. Topic 5: Array versus Struct Topic 6 : Array in Struct. Objectives: In this chapter, you will: Know the different between struct and array Discover how arrays are used in a struct. Arrays versus struct s.

cassie
Download Presentation

C++ Programming: From Problem Analysis to Program Design, Fourth Edition

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C++ Programming: From Problem Analysis to Program Design, Fourth Edition Topic 5: Array versus Struct Topic 6 : Array in Struct Objectives:In this chapter, you will: Know the different between struct and arrayDiscover how arrays are used in a struct

  2. Arrays versus structs C++ Programming: From Problem Analysis to Program Design, Fourth Edition

  3. Arrays versus structs (Continue) Given declaration int arr1[10],arr2[10]; studentRec stud1,stud2; C++ Programming: From Problem Analysis to Program Design, Fourth Edition

  4. Arrays in structs Struct definition: structsalesPerRec {int ID;int age; double saleByQuarter[4]; }; struct declaration: salesPerRec SP1; salesPerRec SP2; C++ Programming: From Problem Analysis to Program Design, Fourth Edition

  5. Arrays in structs (continued) SP1 SP2 C++ Programming: From Problem Analysis to Program Design, Fourth Edition struct SP1 and SP2

  6. Programming Example C++ Programming: From Problem Analysis to Program Design, Fourth Edition

  7. More Programming Example C++ Programming: From Problem Analysis to Program Design, Fourth Edition

  8. Exercise1 1. Add more function: a) Named findAvg that will return the average value for sale by quarter. b) Named findLowest that will display the lowest sales. • Named findIndex that will return the index of highest sales. 2. Write the function calling for all the above functions. C++ Programming: From Problem Analysis to Program Design, Fourth Edition

  9. Exercise2 1. Change the saleByQuarter declaration into two dimensional arrays that have 4 rows and 2 columns. • Write the functions that will: a) input the details of the sales person b) display the sum for each row c) return the highest value for column 0 3. Write the main function that will call all the above functions. C++ Programming: From Problem Analysis to Program Design, Fourth Edition

  10. Exercise 3 Given a struct definition: structstudentRec { char name[40]; char matricNum; double quiz[3]; double test[2]; double final; double totMark; }; C++ Programming: From Problem Analysis to Program Design, Fourth Edition

  11. Exercise 3(continue) Write a function definition that will: • inputData() //this function will input name, matric number, //quizzes mark, test mark and final mark • calcTotQuiz() //this function will calculate and return the total //mark for quizzes • calcTotTest() //this function will calculate and return the total //mark for test • calcTotalMark() //this function will calculate and return the total //mark based on the formula given: Total Mark= (50% of final)+(20% of total test)+(30% of total quiz)

More Related