© Janice Regan, CMPT 102, Sept. 2006 0 CMPT 102 Introduction to Scientific Computer Programming Structures.

Slides:



Advertisements
Similar presentations
Copyright © 2002 Pearson Education, Inc. Slide 1.
Advertisements

EASTERN MEDITERRANEAN UNIVERSITY EENG212 ALGORITHMS & DATA STRUCTURES Structures in C.
Programming in C Chapter 10 Structures and Unions
Introduction to C Systems Programming Concepts. Introduction to C A simple C Program A simple C Program –Variable Declarations –printf ( ) Compiling and.
Programming and Data Structure
© Janice Regan, CMPT 128, February CMPT 128: Introduction to Computing Science for Engineering Students Pointers.
Structures Spring 2013Programming and Data Structure1.
Single Variable and a Lot of Variables The declaration int k; float f; reserve one single integer variable called k and one single floating point variable.
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.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Control Structures Nested ifs, switch statements.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Structures.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Introduction to Arrays.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Introduction to 2-D Arrays.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Functions Call by reference.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Fundamentals of Strings and Characters Characters.
Introduction to Computers and Programming Lecture 17: Arrays (cont) Professor: Evan Korth New York University.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Expressions and Operators Program Style.
Encapsulation by Subprograms and Type Definitions
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Strings.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Conditional Statements Control Structures.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Logical and Relational Expressions Nested if statements.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Pointers.
Introduction Computer program: an ordered sequence of instructions whose objective is to accomplish a task. Programming: process of planning and creating.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Building User Libraries.
1 CSCE 1030 Computer Science 1 Arrays Chapter 7 in Small Java.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Examples of loops and nested loops.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Integer Data representation Addition and Multiplication.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Data representation and Data Types Variables.
Chapter 6 Structures and Classes. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 6-2 Structures  2 nd aggregate data type: struct  Recall:
By Sidhant Garg.  C was developed between by Dennis Ritchie at Bell Laboratories for use with the Unix Operating System.  Unlike previously.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Programing Basics COMP.
 2005 Pearson Education, Inc. All rights reserved. 1 Arrays.
 Introduction to Computer Science COMP 51 – Fall 2012 – Section 2 Structures.
Spring 2005, Gülcihan Özdemir Dağ Lecture 11, Page 1 BIL104E: Introduction to Scientific and Engineering Computing, Spring Lecture 11 Outline 11.1.
Basics of Most C++ Programs // Programmer: Clayton Price date: 9/4/ // File: fahr2celc.cpp 03. // Purpose:
 Structures are like arrays except that they allow many variables of different types grouped together under the same name. For example you can create.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 13: Data structures in C.
1 C Language Structures. 2 Topics Concept of a structure Concept of a structure Structures in c Structures in c Structure declaration Structure declaration.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
C Lecture Notes 1 Structures & Unions. C Lecture Notes Introduction Structures –Collections of related variables (aggregates) under one name Can.
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 1: Introduction Data.
Java Programming: From Problem Analysis to Program Design, Second Edition1 Lecture 5 Objectives  Learn about basic GUI components.  Explore how the GUI.
ITEC 109 Lecture 7 Operations. Review Variables / Methods Functions Assignments –Purpose? –What provides the data? –What stores the data? –What type of.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Introduction to simple functions.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Functions Parameters passed by reference.
11/5/2016CS150 Introduction to Computer Science 1 Announcements  Assignment 6 due on Wednesday, December 3, 2003  Final Exam on Tuesday, December 9,
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Functions (2)
CPS120: Introduction to Computer Science Lecture 16 Data Structures, OOP & Advanced Strings.
Slide 1 Chapter 6 Structures and Classes. Slide 2 Learning Objectives  Structures  Structure types  Structures as function arguments  Initializing.
12/14/2016CS150 Introduction to Computer Science 1 Announcements  Website is up!   All lecture slides, assignments,
1 CS161 Introduction to Computer Science Topic #15.
Multiple Items in one Data Object Arrays are a way to store more than one piece of data in a data object, provided that all the data is of the same type.
© Janice Regan, CMPT 128, Feb CMPT 128: Introduction to Computing Science for Engineering Students Structures.
CSE 251 Dr. Charles B. Owen Programming in C1 structs Aggregating associated data into a single variable Box width length height Circle radius int main()
1 11/30/05CS150 Introduction to Computer Science 1 Structs.
© Janice Regan, CMPT 128, January CMPT 128: Introduction to Computing Science for Engineering Students Introduction to Arrays.
13/10/2016CS150 Introduction to Computer Science 1 Multidimensional Arrays  Arrays can have more than one column  Two dimensional arrays have two columns.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students, continue; and break; statements.
Programming Languages Salihu Ibrahim Dasuki (PhD) CSC102 INTRODUCTION TO COMPUTER SCIENCE.
Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 6-1 Learning Objectives  Structures  Structure types  Pointers and structure types  Structures.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
C++ Basic Input and Output (I/O)
The Machine Model Memory
CS1010 Programming Methodology
Learning Objectives Structures Structure types
Variables and Constants
Presentation transcript:

© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Structures

© Janice Regan, CMPT 102, Sept Structures as Function Arguments  A structure can be passed like any simple data type (whole structure or any element)  Pass-by-value  Pass-by-reference  Or combination  Can also be returned by function  Return-type is the structure type  Return statement in function definition sends structure variable back to caller

© Janice Regan, CMPT 102, Sept Structures and composite members  Structures can include elements that are of aggregate data types  Consider a structure that includes a member that is an array or another structure.  structureIdentifier.memberIdentifier[i]  structureIdentifier1.structureIdentifier2.memberIdentifier  Structures can be members or elements of aggregate data types  Can have and array of structures. To reference a member of the i'th structure in the array StructureIdentifier[i].memberIdentifier

© Janice Regan, CMPT 102, Sept Return to our Example  Define Structure labMeasurement  labMeasurement contains all data regarding the running of a load test on a sample group of components  labMeasurement includes  An integer indicating the date the measurement was taken  An integer indicating the number of components to be tested in the experiment  An integer containing the duration of the experiment is seconds  A floating point number containing the measured temperature in degrees Celsius  A floating point number indicating the number of components that failed the load test in the recorded conditions

© Janice Regan, CMPT 102, Sept Consider our example typedef struct { int measurementNum; int date; int numOfComponents; int duration; double temperature; int numFailures; } labMeasurement;

© Janice Regan, CMPT 102, Sept Add a new structure to our example  Define a new structure experiment  experiment contains all data regarding the running of a series of load tests for a range of conditions and components  experiment includes  An integer indicating the number of labMeasurements in the experiment  An character array of length 80 containing a label explaining the purpose of the particular experiment  A floating point number indicating the percent of tested components that failed in each of the labMeasurements  A floating point number containing the measured temperature in degrees Fahrenheit (converted from the Celsius measurement in the labMeasurement itself)  A floating point number indicating the number of components that failed the load test in the recorded conditions

© Janice Regan, CMPT 102, Sept struct experiment { int numMeasurements; char description[80]; double percentFailures[MAXEXP]; double tempScaled[MAXEXP]; labMeasurement measures[MAXEXP]; };

© Janice Regan, CMPT 102, Sept New experiment structure  The experiment structure illustrates several ways of using composite variables as members of a structure.  The description variable containing a label describing the experiment is a character array.  The scaled temperature and percent of components that failed are arrays of double variables. The ith element of each of these arrays correspond to the ith labMeasurement that is part of the experiment  The array of labMeasurement structures measures illustrates that not only can we have arrays as members of a structure we can also have other structures or even arrays of those other structures

© Janice Regan, CMPT 102, Sept Accessing elements (1)  Consider accessing individual elements of arrays that are members of a structure e1 of type experiment. struct experiment e1; /* values of members of e1 are set */ e1.percentFailures[k] = 24.3; outint = e1.tempScaled[k];

© Janice Regan, CMPT 102, Sept Accessing elements (2)  Consider accessing members of individual elements of an array of structures of type experiment. Each element of the array of structures is a structure of type experiment. struct experiment e1; labMeasurement L1; /* The k th element of the array of structures is assigned to */ /* labMeasurement structure L1. Each member of L1 will then */ /* contain the same value as the corresponding member of */ /* experiment struture e1.measures[k] */ L1 = e1.measures[k]; celsiusTemp = e1.measure[k].temperature; /* statement above is equivalent to celsiusTemp = L1.temperature */