11/5/2016CS150 Introduction to Computer Science 1 Announcements  Assignment 6 due on Wednesday, December 3, 2003  Final Exam on Tuesday, December 9,

Slides:



Advertisements
Similar presentations
C Language.
Advertisements

Introduction to Programming Lecture 39. Copy Constructor.
Structures Spring 2013Programming and Data Structure1.
Structures in C.
Chapter 3 DATA: TYPES, CLASSES, AND OBJECTS. Chapter 3 Data Abstraction Abstract data types allow you to work with data without concern for how the data.
An Array A sequence of elements of a particular type Each element in the array has an index which gives its position in the sequence An array is declared.
Arrays Chapter 6. Outline Array Basics Arrays in Classes and Methods Sorting Arrays Multidimensional Arrays.
1 11/05/07CS150 Introduction to Computer Science 1 Functions Chapter 6, page 303.
Structures, Unions, and Typedefs CS-2301 D-term Structures, Unions, and Typedefs CS-2301 System Programming D-term 2009 (Slides include materials.
Computer Science 1620 Multi-Dimensional Arrays. we used arrays to store a set of data of the same type e.g. store the assignment grades for a particular.
©2004 Brooks/Cole Chapter 8 Arrays. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Sometimes we have lists of data values that all need to be.
C structures and unions (Reek, Ch. 10) 1CS 3090: Safety Critical Programming in C.
PHYS 2020 Making Choices; Arrays. Arrays  An array is very much like a matrix.  In the C language, an array is a collection of variables, all of the.
Structures and UnionsCS-2301 B-term Structures and Unions CS-2301, System Programming for Non-majors (Slides include materials from The C Programming.
1 The first step in understanding pointers is visualizing what they represent at the machine level. In most modern computers, main memory is divided into.
7.1 Arrays Introduction to arrays Any array is a collection of objects or primitives Useful when the number of reference variables is large or.
More Storage Structures A Data Type Defined by You Characteristics of a variable of a specific ‘data type’ has specific values or range of values that.
Chapter 11: Structured Data. Slide Introduction An array makes it possible to access a list or table of data of the same data type by using a single.
1 Introduction to Arrays Problem: –Input 5 scores, compute total, average –Input Example –test scores,employees,temperatures.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 11. The Struct Data Type.
Cosc237/structures1 Structures aggregate data types record - single variable name for the whole collection composed of several variables - fields,BUT,
Learners Support Publications Classes and Objects.
 Introduction to Computer Science COMP 51 – Fall 2012 – Section 2 Structures.
Chapter 11: Pointers Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 11 Pointers.
1 CS 132 Spring 2008 Chapter 3 Pointers and Array-Based Lists read p
111/15/2015CS150 Introduction to Computer Science 1 Summary  Exam: Friday, October 17,  Assignment: Wednesday, October 15, 2003  We have completed.
5/3/01 Sudeshna Sarkar, CSE, IIT Kharagpur1 Structures Lecture
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
 Structures are like arrays except that they allow many variables of different types grouped together under the same name. For example you can create.
1 CS161 Introduction to Computer Science Topic #17.
Chapter 13: Structures. In this chapter you will learn about: – Single structures – Arrays of structures – Structures as function arguments – Linked lists.
1 C Language Structures. 2 Topics Concept of a structure Concept of a structure Structures in c Structures in c Structure declaration Structure declaration.
Structures (L30) u Syntax of a struct Declaration u Structure Variables u Accessing Members of Structures u Initialize Structure Variables u Array of Structures.
ECE 103 Engineering Programming Chapter 50 Structures Unions, Part 2 Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE.
Copyright © 2002 W. A. Tucker1 Chapter 9 Lecture Notes Bill Tucker Austin Community College COSC 1315.
1 Chapter 12 Arrays. 2 C++ Data Types structured array struct union class address pointer reference simple integral enum char short int long bool floating.
UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming1 Arrays.
Chapter 8 Arrays. A First Book of ANSI C, Fourth Edition2 Introduction Atomic variable: variable whose value cannot be further subdivided into a built-in.
1 CS161 Introduction to Computer Science Topic #15.
© Janice Regan, CMPT 128, Feb CMPT 128: Introduction to Computing Science for Engineering Students Structures.
1. 2 Introduction Structure Definitions and Declarations Initializing Structures Operations on Structures Members Structures as Functions Parameters Array.
Struct s (7.4) Used as data aggregates for an entity can be different types of data e.g. for student id, name, GPA, address,... Similar to classes, but.
Extra Recitations Wednesday 19:40-22:30 FENS L055 (tomorrow!) Friday 13:40-16:30 FENS L063 Friday 17: :30 FENS L045 Friday 19:40-22:30 FENS G032.
1 11/30/05CS150 Introduction to Computer Science 1 Structs.
Array and Pointers An Introduction Unit Unit Introduction This unit covers the usage of pointers and arrays in C++
13/10/2016CS150 Introduction to Computer Science 1 Multidimensional Arrays  Arrays can have more than one column  Two dimensional arrays have two columns.
CS 1430: Programming in C++ 1. File Input in VS Project Properties Debugging Command Arguments quiz8-1.out We want to know how to do it ourselves, right?
Introduction to programming in java Lecture 22 Arrays – Part 2 and Assignment No. 3.
Chapter 11 Structures, Unions and Typedef 11.1 Structures Structures allow us to group related data items of different types under a common name. The individual.
CS 100Lecture 221 Announcements P5 due Thursday Final Exam: Tuesday August 10, 8AM - 10AM, Olin 155 Want references? Remember to drop off a picture and.
1 C++ Data Types structured array struct union class address pointer reference simple integral enum char short int long bool floating float double long.
Beginning C for Engineers Fall 2005 Arrays, 2-D arrays, character strings Bettina Schimanski Lecture 5: Section 2 (9/28/05) Section 4 (9/29/05)
KUKUM-06/07 EKT120: Computer Programming 1 Week 6 Arrays-Part 1.
CS150 Introduction to Computer Science 1
C++ Arrays.
CS 1430: Programming in C++.
CS150 Introduction to Computer Science 1
CS150 Introduction to Computer Science 1
Classes and Objects.
CS150 Introduction to Computer Science 1
CS111 Computer Programming
CS150 Introduction to Computer Science 1
CS150 Introduction to Computer Science 1
CS150 Introduction to Computer Science 1
CS150 Introduction to Computer Science 1
CS150 Introduction to Computer Science 1
Chapter 9: Pointers and String
CS150 Introduction to Computer Science 1
Structure (i.e. struct) An structure creates a user defined data type
Structures, Unions, and Enumerations
Presentation transcript:

11/5/2016CS150 Introduction to Computer Science 1 Announcements  Assignment 6 due on Wednesday, December 3, 2003  Final Exam on Tuesday, December 9, 2003 at 3pm

21/5/2016CS150 Introduction to Computer Science 1 Multidimensional Array  A class contains 3 students and each of these students have taken 4 tests. Write a program that will read in the students grades from a file, then print them to the screen along with the largest and smallest grades overall and the average grade of each student. [0] [1] [2] [3] Student[0] Student[0] Student[0] The largest grade is: 96 The smallest grade is: 68 The average grade for student 0 is The average grade for student 1 is The average grade for student 2 is 81.75

31/5/2016CS150 Introduction to Computer Science 1 Arrays and Data Types  Useful for storing a collection of data elements of the same data type (float, int, string). char myName[5]; //All elements chars float salaries[NUM_EMP]; //All elements floats char vowels[]={ ‘ A ’, ’ E ’, ’ I ’, ’ O ’, ’ U ’ }; int matrix[3][5];  What about storing a collection of data elements of different data types?

41/5/2016CS150 Introduction to Computer Science 1 Data with Different Data Types  For example, what if we wanted to keep the following information on a particular employee: employee id SS# number of children salary citizen  The elements have different data types, so we can’t conveniently use an array. Instead we will use a struct ( short for structure).

51/5/2016CS150 Introduction to Computer Science 1 Structure Definition To store this information: employee id SS# number of children salary citizen We would begin by defining a structure : struct employ { int id int ssnum; int numchild; float salary; bool citizen; };

61/5/2016CS150 Introduction to Computer Science 1 Struct Terminology For this struct: struct employ { int id int ssnum; int numchild; float salary; bool citizen; };  employ is the identifier name and a NEW data type.  The individual components id, ssnum, etc. are called members.

71/5/2016CS150 Introduction to Computer Science 1 Struct Declaration  As with all data types, in order to use our new data type employ we must allocate storage space by declaring variables of this data type: employ engineer,tech;  This will allocate space for two variables called engineer and tech with the previously described members id, ssnum, etc.

81/5/2016CS150 Introduction to Computer Science 1 Member Access Operator  To access a struct member, we use the member access operator (period between struct variable name and member name).  In the variable engineer of data type employ we can make the assignments: engineer.id = 12345; engineer.ssnum = ; engineer.numchild = 2; engineer.salary = ; engineer.citizen = true;  How do we access the data in arrays?

91/5/2016CS150 Introduction to Computer Science 1 Example One  Write a C++ struct data type realnum that will have members number, realpart, and intpart.  Declare a variable numinfo of that type.  Place the value in the field number.

101/5/2016CS150 Introduction to Computer Science 1 Example One Solution struct realnum { float number; int realpart; int intpart; }; realnum numinfo; numinfo.number= ; Define struct realnum Declare variable numinfo Assign member number

111/5/2016CS150 Introduction to Computer Science 1 Structs as function arguments  Structs can be passed to functions by reference or value in the same manner that other data types have been passed.  Generally, passing structs by reference is preferred since passing by value requires a local copy of the struct be created within the function’s variables.

121/5/2016CS150 Introduction to Computer Science 1 Example Two  Write a C++ function split that accepts a variable of type realnum.  Assign the integer part of the number to the member variable intpart and the real part of the number to the member variable realpart.

131/5/2016CS150 Introduction to Computer Science 1 Example Two Solution  Function prototype: void split(realnum &);  Function call: split (numinfo);  Function definition: void split(realnum & numberinfo) { // Use numberinfo.number,numberinfo.intpart, // and numberinfo.realpart. }

141/5/2016CS150 Introduction to Computer Science 1 Example Three Consider the following struct data type: struct info { int num; int divisors[10]; int howmany; }; Write a C++ function compute that accepts a variable of type info and returns all the divisors greater than 1 of the variable num in the array divisors and the number of divisors in the variable howmany.