After those declarations we assigned 2 records and give them their values:

Similar documents
Column_Major_Display: For I in For J in Location_In_Array := I + (J-1)*3 Display Element in Array(Location_In_Array) New_Line

Q1: Functions / 33 Q2: Arrays / 47 Q3: Multiple choice / 20 TOTAL SCORE / 100 Q4: EXTRA CREDIT / 10

Introduction to Computers and Programming. Structured data types

Lecture C11: FOR, WHILE and General Loops

How to declare an array in C?

Lecture Transcript While and Do While Statements in C++

Q1: Multiple choice / 20 Q2: Arrays / 40 Q3: Functions / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

Dynamic Memory Allocation

Introduction. Primitive Data Types: Integer. Primitive Data Types. ICOM 4036 Programming Languages

Programming in OOP/C++

So on the survey, someone mentioned they wanted to work on heaps, and someone else mentioned they wanted to work on balanced binary search trees.

An array is a collection of data that holds fixed number of values of same type. It is also known as a set. An array is a data type.

CMSC202 Computer Science II for Majors

The easiest way to get these data into STATA is for you to fire up the STATA Data Editor and just type the data into the spreadsheet-like interface.

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #34. Function with pointer Argument

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #43. Multidimensional Arrays

CMSC 202. Pointers Dynamic Memory Allocation

C:\Temp\Templates. Download This PDF From The Web Site

What is an algorithm?

CpSc 1111 Lab 9 2-D Arrays

Notes on Chapter 1 Variables and String

16.216: ECE Application Programming Spring 2015 Exam 2 Solution

Module 10A Lecture - 20 What is a function? Why use functions Example: power (base, n)

CS Lecture #6. Administrative... Assignment #2 Graded NN Turned In, Average Grade: XX Assignment #3 due on Thursday

Goals of this Lecture

Arrays IT 1033: Fundamentals of Programming

INTERMEDIATE SQL GOING BEYOND THE SELECT. Created by Brian Duffey

DECLARAING AND INITIALIZING POINTERS

Symbol Tables. ASU Textbook Chapter 7.6, 6.5 and 6.3. Tsan-sheng Hsu.

CSE Spring 2015 Homework #1 Assigned January 22 nd, 2015, 2:00 pm Due: February 5 th, 2015, 2:00 pm

SORTING AND SEARCHING

Chapter 11 Introduction to Programming in C

I2204 ImperativeProgramming Semester: 1 Academic Year: 2018/2019 Credits: 5 Dr Antoun Yaacoub

Control Abstraction. Hwansoo Han

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #17. Loops: Break Statement

(Refer Slide Time: 05:25)

Get JAVA. I will just tell you what I did (on January 10, 2017). I went to:

CSCI312 Principles of Programming Languages!

(Refer Slide Time 01:41 min)

Comp 11 Lectures. Mike Shah. June 26, Tufts University. Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

Data Representation and Storage. Some definitions (in C)

Operating Systems. 09. Memory Management Part 1. Paul Krzyzanowski. Rutgers University. Spring 2015

At this time we have all the pieces necessary to allocate memory for an array dynamically. Following our example, we allocate N integers as follows:

Before we start - Announcements: There will be a LAB TONIGHT from 5:30 6:30 in CAMP 172. In compensation, no class on Friday, Jan. 31.

Create a Login System in Visual Basic. Creating a login system. Start a new visual basic Windows Forms application project. Call it Login System

UNIT I Programming Language Syntax and semantics. Kainjan Sanghavi

Run Time Environment

How to Use the STATA infile and infix Commands

Semantic actions for expressions

Review 1/2 MIPS assembly language instructions mapped to numbers in 3 formats. CS61C Negative Numbers and Logical Operations R I J.

Creating a new form with check boxes, drop-down list boxes, and text box fill-ins. Customizing each of the three form fields.

LBSC 690: Information Technology Lecture 05 Structured data and databases

Chapter 11 Introduction to Programming in C

CS3157: Advanced Programming. Announcement

Problem Set 5 Solutions

Lecture 14. Arrays II. Selection Sort & Parallel Arrays. CptS 121 Summer 2016 Armen Abnousi

(Refer Slide Time: 00:26)

CSCE 2014 Final Exam Spring Version A

public class Foo { private int var; public int Method1() { // var accessible anywhere here } public int MethodN() {

Chapter 19 Data Structures

EE 355 Lab 4 - Party Like A Char Star

To become familiar with array manipulation, searching, and sorting.

C++ for Java Programmers

Spring 2013 CS 122C & CS 222 Midterm Exam (and Comprehensive Exam, Part I) (Max. Points: 100)

Parallel Transport on the Torus

Intro to Computer Science II

Programming Languages

CS 31: Intro to Systems Pointers and Memory. Kevin Webb Swarthmore College October 2, 2018

AIMS Embedded Systems Programming MT 2017

This handbook contains directions on using tools and resources in WebAccess at CSM.

Lecture 5 - Control Structure Applications

Pointer Basics. Lecture 13 COP 3014 Spring March 28, 2018

a data type is Types

Introduction to C++ with content from

Dan Greenberg Senior Design Project

Structs. Comp Sci 1570 Introduction to C++ Introduction. Aggregate data. Example. General syntax Object initialization Initialization and access

Computer Science & Engineering 150A Problem Solving Using Computers

Computer (Literacy) Skills. Variables, records, and pointers. Lubomír Bulej KDSS MFF UK

Data Structures and Algorithms

Programming Languages

Skill 1: Multiplying Polynomials

A collision is said to occur when two or more keys hash to the same index location.

CS 31: Intro to Systems Pointers and Memory. Martin Gagne Swarthmore College February 16, 2016

CS 3343 (Spring 2013) Exam 2

Lastly, in case you don t already know this, and don t have Excel on your computers, you can get it for free through IT s website under software.

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #16 Loops: Matrix Using Nested for Loop

Fundamentals of Programming Languages

CS201 Some Important Definitions

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

There are functions to handle strings, so we will see the notion of functions itself in little a detail later. (Refer Slide Time: 00:12)

CS2110 Fall 2015 Assignment A5: Treemaps 1

WELCOME TO CS 16! Problem Solving with Computers-I

CS 314 Principles of Programming Languages

Documentation Nick Parlante, 1996.Free for non-commerical use.

Arizona s First University. More ways to show off--controlling your Creation: IP and OO ECE 373

Arrays and functions Multidimensional arrays Sorting and algorithm efficiency

Largest Online Community of VU Students

CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline

Basic Types & User Defined Types

Lecture 7: Examples, MARS, Arithmetic

Transcription:

Lecture C16: Records Response to 'Muddiest Part of the Lecture Cards' (38 respondents) 1) In defining record 'My_First_Record' you just said ("Name", "Age", "Location") Is that acceptable? Shoouldn't you define each input separately? (1 student) I assume it is the code for Concept question 1 you are refering to. There is no input operations at all in that file. The record is declared at the top, where each field in the record gets its name and what type each field should be. type My_Record_1 is record Name : String (1..10); Age : Integer; Location : String ( 1..10); After those declarations we assigned 2 records and give them their values: My_First_Record : My_Record_1 := ("John Doe ", 25,"Detroit Mi"); My_Second_Record : My_Record_2 := ("Jane Doe ", 30,"New York "); Which meens that "My_First_Record" is a record of type 'My_Record_1' and at the same time gets assigned values for each field. Within the main section of the procedure we then perform operations on these two reocrds, My_First_Record and My_Second_Record. 2) In your code, you often use Put("Blah"), but when I've tried this command, I get a compilation error. I have to use Ada.Text_Io.Put("Blah"); Why? (1 student) That is correct. You will always have to use the correct IO routines for the kind of types you want to read/print. I very often exclude the lines e.g, "With Ada.Text_IO; use Ada.Text_IO;" in my examples to save space and time. 3) How can we make fields within fields? (1 student) Take a look at the Ada file "complex_persons.adb" that was distributed in class. It defines a record with in a record. That is, the field "Name" is in it self a record with 3 fields for "Title, First name, and Surname".

--variable declarations type Inner_Record is record Field_1 : Integer; Field_2 : Character; type Outer_Record is record Field_A : Integer; Inner_Record_Name : Inner_Record; Outer_Record_Name : Outer_Record; -- main program Outer_Record_Name.Inner_Record_Name.Field_In_Inner_Record The. Operator allows the programmer to access fields of the record. The same operator used in succession can be used to access fields of inner records. 4) What is the point of using arrays, how are they different from records? and similar questions (4 students) Arrays are used to store homogenous data (data of the same type). A record on the other hand, can have data of different types as its fields. You can, for instance, have:

- an array of records - a record containing an array as a field 5) When someone enters info into a record, do you have to previously declare what record name it goes under (like A_Person. ) What if you dont know how many people you want to enter? (1 student) If you don t know the number of records you want to enter, there are two possible approaches: a. Declare an array of records (static allocation) b. Use dynamic memory allocation The size of the array is the largest number of records that you might want. This approach however wastes a lot of memory. An alternative approach is to use dynamic memory allocation, which we will cover next semester. 6) how do we sort records or find records based on a single field? (1 student) Instead of checking for the element value, check the field value. For example: -- variable declaration type My_Aircraft is record Id : Integer; Latitude : Float; Longitude : Float;

-- sorting procedure for I in 1.. Num_Of_Aircraft - 1 loop for J in I+1.. Num_Of_Aircraft loop end loop; end loop; if Input_Array(I).Latitude > Input_Array(J).Latitude then end if; Temp:= Input_Array(I); Input_Array(I) := Input_Array(J); Input_Array(J) := Temp; 7) Why are two records with the same data of different types? (1 student) As far as the compiler is concerned, they are defined as different types and can have different operations associated with them. 8) What does "(others => space);" do? (1 students) The others=> space operations is called the aggregation operation. It fills the remaining fields with blank spaces. 9) Is there a way to display the entire record by a single command? (1 student) You can write a procedure to display each of the fields and call the procedure. Other than that, there is no predefined Ada library function that will allow you to display all the elements in a record. 10) Is there a way to make actual tables in Ada? Without teadious hand formating, like with borders and stuff? (1 students) 11) What is the purpose of Nchar in the second code example? (1 student) Nchar keeps track of how many characters have been entered as input. That information is never used in the code, so it should have been removed. 12) How can I get an input from the user and stay on the same line? that is, I want to print something on the same line as something I get? (1 student) Move the Skip_Line command to the line after you display your outputs. This will allow you to display

output on the same line. 13) Give me pointers, we are so close now! (1 student) Yes we are... and pointer will be covered in beginning of spring term. 14) Handling files, making columns and screen formating? and similar questions (4 students) Will be covered more next term. 15) "No mud" (15 students) Good :-)