1 Lecture 32 Handling Selected Topics Again!! Structs and Arrays of Structs Special Lectures.

Slides:



Advertisements
Similar presentations
CSEB324 Data Structures & Algorithms
Advertisements

Programming in C Chapter 10 Structures and Unions
Structure.
Student Data Score First Name Last Name ID GPA DOB Phone... How to store student data in our programs? 1.
CSC141- Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 25 Thanks for Lecture Slides: Dr. Sadaf Tanveer Dr. Sadaf Tanveer,
Structures. An array allows us to store a collection of variables However, the variables must be of the same type to be stored in an array E.g. if we.
1 Chapter Structured Types, Data Abstraction and Classes Dale/Weems.
Strings and Arrays The objectives of this chapter are:  To discuss the String class and some of its methods  To discuss the creation and use of Arrays.
1 Lecture 24 Chapter 11 Structured Types, Data Abstraction and Classes Dale/Weems/Headington.
1 Lab Session-1 CSIT221 Spring 2003 b Group Programming Challenge b Individual Lab Exercise (Demo Required)
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
© The McGraw-Hill Companies, 2006 Chapter 5 Arrays.
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.
1 Lab Session-III CSIT-120 Spring 2001 Revising Previous session Data input and output While loop Exercise Limits and Bounds GOTO SLIDE 13 Lab session.
INTRODUCTION TO PYTHON PART 2 INPUT AND OUTPUT CSC482 Introduction to Text Analytics Thomas Tiahrt, MA, PhD.
CS0007: Introduction to Computer Programming Introduction to Arrays.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 23P. 1Winter Quarter Structs and Enumeration.
Classes Java is an Object-Orented Programming language, and one of the main advantages of OOP is code reuse. Code reuse: write code only once, put it in.
WebConnect For Substitutes Part of SubFinder’s advanced series of Web related products.
WebConnect FOR SUBSTITUTES Part of SubFinder’s advanced series of Web related products.
Computer Programming 2 Lab(1) I.Fatimah Alzahrani.
Structure A structure is a collection of variables of different data type under one name. It is a derived data type. e.g. struct employee {int empno; char.
1 C++ Syntax and Semantics, and the Program Development Process.
Learners Support Publications Classes and Objects.
CSCI 383 Object-Oriented Programming & Design Lecture 6 Martin van Bommel.
1 Chapter 11 Structured Types, Data Abstraction and Classes Dale/Weems/Headington.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 23P. 1Winter Quarter Structs and Enumeration Lecture 23.
Array, Structure and Union
Data Structures: Arrays Damian Gordon. Arrays Imagine we had to record the age of everyone in the class, we could do it declaring a variable for each.
1 Data Structures. 2 Motivating Quotation “Every program depends on algorithms and data structures, but few programs depend on the invention of brand.
Research Topics in Computational Science. Agenda Survey Overview.
Chapter 13: Structures. In this chapter you will learn about: – Single structures – Arrays of structures – Structures as function arguments – Linked lists.
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.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
CS 139-Programming Fundamentals Lecture 11B - Arrays Adapted from a presentation by Dr. Rahman Fall 2014.
CSC 212 – Data Structures Lecture 2: Primitives, References, & Classes.
CPS120: Introduction to Computer Science Lecture 15A Structures.
Quiz // // The function exchanges the two parameters. // Param: ( ) // Param:
1 CSC103: Introduction to Computer and Programming Lecture No 24.
11/5/2016CS150 Introduction to Computer Science 1 Announcements  Assignment 6 due on Wednesday, December 3, 2003  Final Exam on Tuesday, December 9,
DATA STRUCTURE & ALGORITHMS Pointers & Structure.
UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming1 Arrays.
Variables and Strings. Variables  When we are writing programs, we will frequently have to remember a value for later use  We will want to give this.
CPS120: Introduction to Computer Science Lecture 16 Data Structures, OOP & Advanced Strings.
COMPUTER PROGRAMMING 2 ArrayLists. Objective/Essential Standard Essential Standard 3.00Apply Advanced Properties of Arrays Essential Indicator 3.02 Apply.
1 CS161 Introduction to Computer Science Topic #15.
Arrays. Topics to be Covered... Arrays ◦ Declaration ◦ Assigning values ◦ Array manipulation using loops Multi-dimensional arrays ◦ 2D arrays ◦ Declaration.
1 Lecture10: Structures, Unions and Enumerations 11/26/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
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.
Pointer Lecture 2 Course Name: High Level Programming Language Year : 2010.
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.
In C programming, one of the frequently arising problem is to handle similar types of data. For example: If the user want to store marks of 100 students.
Chapter 5: Arrays in Java. The objectives of this chapter are:  1. To discuss the creation and use of Arrays.   2. To continue to use the String class.
13/10/2016CS150 Introduction to Computer Science 1 Multidimensional Arrays  Arrays can have more than one column  Two dimensional arrays have two columns.
Chapter 6. Character String Types It is one in which the values consists of sequences of characters. How to Define a variable contain a string? In a programming.
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.
Lecture 2 Arrays. Topics 1 Arrays hold Multiple Values 2 Accessing Array Elements 3 Inputting and Displaying Array Contents 4 Array Initialization 5 Using.
Introduction to programming in java Lecture 21 Arrays – Part 1.
KUKUM-06/07 EKT120: Computer Programming 1 Week 6 Arrays-Part 1.
CS150 Introduction to Computer Science 1
Structures Lesson xx In this module, we’ll introduce you to structures.
CS150 Introduction to Computer Science 1
CS148 Introduction to Programming II
Objectives In this chapter, you will: - Learn about records (structs) - Examine operations on a struct - Manipulate data using a struct - Learn about the.
Exercise Solution First questions What's output What's input
See requirements for practice program on next slide.
CS149D Elements of Computer Science
Arrays, Casting & User Defined Variables
Presentation transcript:

1 Lecture 32 Handling Selected Topics Again!! Structs and Arrays of Structs Special Lectures

2 Motivation l We may have different types of data about a single item of interest l For example, a cat’s color is a string, its age in years is an integer and its weight is a floating point number l A student’s name is a string, SS# is a long integer and GPA is a float value l To collect different types of data about an item of interest, we use “struct” data type in C++

3 Struct Declaration Syntax l struct name { l member1; l member2; l. l }; l Variables of this type declared later

4 Struct Examples l Let us declare some example structs l struct cat l struct student l struct employee l (In employee struct, we can define name, ID number and date of hiring as members)

5 Using Structs in Programs l Declare two cats named Kitty and Mely. Kitty is of brown color and weighs 19.2 lbs and is 4 years old. Mely is a 6 years old white cat weighing 23.5 lbs l If the difference between the weights of these two cats is less than three times the difference between their ages, the program should display the message “Older one is under-weight”

6 Arrays of Structs: A Program l Arrays are convenient for bringing huge amounts of data under a common name l For example, a building manager maintains a list of residents in a computer program. There are a total of 150 apartments in the building. The manager has to maintain the name of the tenant, tenant’s home phone number, emergency phone number and the security code assigned to the tenant for opening the main entrance door of the building

7 Practice Program l Write a program that declares necessary data structures to hold all this information about residents of the 150 apartments. Apartments are numbered 1 through 150 l Write a function to check if a new code number being allocated to a tenant is not already allocated l Write a function to count how many apartments are empty (Empty apartments have the security code reduced to 0)