Computer Programming Arrays 1. Question #1 2 Question Choose the correct answer..

Slides:



Advertisements
Similar presentations
Chapter 9 – One-Dimensional Numeric Arrays. Array u Data structure u Grouping of like-type data u Indicated with brackets containing positive integer.
Advertisements

Etter/Ingber Arrays and Matrices. Etter/Ingber One-Dimensional Arrays 4 An array is an indexed data structure 4 All variables stored in an array are of.
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
1 Arrays Chapter 9. 2 Outline  The array structure (Section 9.1)  Array declaration  Array initialization  Array subscripts  Sequential access to.
True or false A variable of type char can hold the value 301. ( F )
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
1 11/3/08CS150 Introduction to Computer Science 1 Reading from and Writing to Files Section 3.12 & 13.1 & 13.5.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
CS31: Introduction to Computer Science I Discussion 1A 5/7/2010 Sungwon Yang
CS150 Introduction to Computer Science 1
1 10/29/07CS150 Introduction to Computer Science 1 Reading from and Writing to Files Section 3.12 & 13.1 & 13.5.
Chapter 8. 2 Objectives You should be able to describe: One-Dimensional Arrays Array Initialization Arrays as Arguments Two-Dimensional Arrays Common.
1 10/9/06CS150 Introduction to Computer Science 1 for Loops.
Multiple-Subscripted Array
Chapter 8 Arrays and Strings
CSE202: Lecture 14The Ohio State University1 Arrays.
Arrays. Objectives Learn about arrays Explore how to declare and manipulate data into arrays Learn about “array index out of bounds” Become familiar with.
1 10/25/06CS150 Introduction to Computer Science 1 Reading from and Writing to Files.
C++ Basics CSci 107. A C++ program //include headers; these are modules that include functions that you may use in your //program; we will almost always.
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
CHAPTER 07 Arrays and Vectors (part I). OBJECTIVES 2 In this part you will learn:  To use the array data structure to represent a set of related data.
Chapter 8 Arrays and Strings
Problem: A company employs a group of fifty salespersons (with reference numbers ) who are paid commission if their individual sales exceeds two-thirds.
EGR 2261 Unit 8 One-dimensional Arrays  Read Malik, pages in Chapter 8.  Homework #8 and Lab #8 due next week.  Quiz next week.
CS31: Introduction to Computer Science I Discussion 1A 4/9/2010 Sungwon Yang
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Arrays.
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
CHAPTER 7 arrays I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
 2003 Prentice Hall, Inc. All rights reserved. 1 Arrays Outline Introduction Arrays Declaring Arrays Examples Using Arrays.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 13 October 13, 2009.
Introduction to Programming Lecture 11. ARRAYS They are special kind of data type They are special kind of data type They are like data structures in.
Section 5 - Arrays. Problem solving often requires information be viewed as a “list” List may be one-dimensional or multidimensional List is implemented.
Introduction to C Programming Lecture 6. Functions – Call by value – Call by reference Arrays Today's Lecture Includes.
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
A First Book of C++: From Here To There, Third Edition2 Objectives You should be able to describe: One-Dimensional Arrays Array Initialization Arrays.
Arrays. Related data items Collection of the same types of data. Static entity – Same size throughout program.
Function Overloading Two different functions may have the same name as long as they differ in the number or types of arguments: int max(int x, int y) and.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 6 Arrays.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter Array Basics.
CHAPTER 6 ARRAYS IN C++ 2 nd Semester King Saud University College of Applied studies and Community Service CSC 1101 By: Fatimah Alakeel Edited.
COMPUTER PROGRAMMING. Array C++ provides a data structure, the array, which stores a fixed-size sequential collection of elements of the same type. An.
Sahar Mosleh California State University San MarcosPage 1 One Dimensional Arrays: Structured data types.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 2 September 3, 2009.
Literals A literal (sometimes called a constant) is a symbol which evaluates to itself, i.e., it is what it appears to be. Examples: 5 int literal
Character Sequences. strings are in fact sequences of characters, we can represent them also as plain arrays of char elements. For example, the following.
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
1 Lecture 4: Part1 Arrays Introduction Arrays  Structures of related data items  Static entity (same size throughout program)
Array. Array is a group of data of the same type. Array elements have a common name –The array as a whole is referenced through the common name Individual.
Introduction to programming in java Lecture 21 Arrays – Part 1.
CS 240 Computer Programming 1
Basic concepts of C++ Presented by Prof. Satyajit De
Chapter 6 Arrays in C++ 2nd Semester King Saud University
Chapter 2 Assignment and Interactive Input
CSC 113: Computer Programming (Theory = 03, Lab = 01)
Introduction to C++ October 2, 2017.
C++ Arrays.
One-Dimensional Array Introduction Lesson xx
Introduction to C++ Programming
Introduction to Programming
Counting Loops.
CS150 Introduction to Computer Science 1
CISC181 Introduction to Computer Science Dr
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
CS 101 First Exam Review.
C++ Basics CSci 107. A C++ program //include headers; these are modules that include functions that you may use in your //program; we will almost always.
Data Structure(s) A way of storing and organizing data in a computer so that it can be used efficiently. e.g. Arrays Linked Lists stacks Queues Trees.
Presentation transcript:

Computer Programming Arrays 1

Question #1 2 Question Choose the correct answer..

1.Which of the following correctly declares an array? A. int anarray[10]; B. int anarray; C. anarray{10}; D. array anarray[10]; 3 Question #1 Question Answer

2. What is the index number of the last element of an array with 29 elements? A. 29 B. 28 C. 0 D. Programmer-defined 4 Question #1 Question Answer

3. Which of the following is a two- dimensional array? A. array anarray[20][20]; B. int anarray[20][20]; C. int array[20, 20]; D. char array[20]; 5 Question #1 Question Answer

4. Which of the following correctly accesses the seventh element stored in foo, an array with 100 elements? A. foo[6]; B. foo[7]; C. foo(7); D. foo; 6 Question #1 Question Answer

5. If char catname[15];, which of the following is valid ? A. catname[15] = 'milie'; B. catname = 'milie'; C. catname[] = 'milie'; D. none are valid. 7 Question #1 Question Answer

8 Question #2 Question * Write one or more statements that perform the following tasks for an array called fractions:

9 Question #2 Question Answer Const int arraySize=10; Define a constant integer variable arraySize initialized to 10.

10 Question #2 Question Answer Double fractions[arraySize]={0.0}; Declare an array with arraySize elements of type double, and initialize the elements to 0.

11 Question #2 Question Answer fractions[9]=1.667; Assign the value to array element 9.

12 Question #2 Question Answer fractions[6]= 3.333; Assign the value to the seventh element of the array.

13 Question #2 Question Answer Cout<<" elements 6 ="<< fractions[6] <<" elements 9="<< fractions[9]; Print array elements 6 and 9.

14 Question #2 Question Answer for ( int i = 0; i < arraySize; ++i ) cout << "fractions[" << i << "] = " << fractions[ i ] << endl; Print all the array elements using a for statement. Define the integer variable i as a control variable for the loop.

15 Question #3 Question Trace the following programs, and show the output:

16 Question #3 int array [] = {16, 2, 3, 4, 8}; int n, result=0; int main () { for ( n=0 ; n<5 ; n++ ) { result += array[n]; } cout << result << endl; return 0; }

17 Question #3 Answer resultArray [n]nLoop # Press any key to continue...

18 Question #3 char question[] = "Please, enter your first name: "; char greeting[] = "Hello, "; char yourname [80]; cout << question; cin >> yourname; cout << greeting << yourname << "!" << endl;

19 Question #3 Answer Please, enter your first name: Hadeel Hello, Hadeel ! Press any key to continue...

20 Question #4 Question Find the error(s) in each of the following statements:

21 Question #4 Question Answer Index out of bound If they meant to print the three numbers in the array, then they should have used a[0], a[1], a[2] Assume that: int a[ 3 ]; cout << a[ 1 ] << " " << a[ 2 ] << " " << a[ 3 ] << endl;

22 Question #4 Question Answer Too many initializers - at most 3 if they've declared f[3] double f[4]= {1.1,10.01, , }; double f[ 3 ] = { 1.1, 10.01, , };

programming 23

24 Problem #1 Question Write a program that calculates the number of occurrences of an integer x in an array of n integers. How many integers you want to enter: 8 Enter the numbers: Which number you want to find its occurrences: 8 8 occurs 3 times

25 Question #1 Answer

26 Problem #1

27 Problem #2 Question Write a C++ program that reads 10 numbers from the user to initialize one dimensional array. Then if the number is greater than or equal to 10, convert it to 1, otherwise convert it to 0. please Enter (10) numbers: The array is :

28 Question #2 Answer

29 Question #2 Answer

30 Problem #3 Question Write a program that asks the user to type 10 integers of an array. The program must output the largest element in the array, and the index at which that element was found Enter 10 integer: The largest number is 56 at index 5

31 Question #3 Answer

32 Question #3 Answer

33 Problem #4 Question Write a program that reads a string then check if the string is Palindrome. NOTE: - a palindrome is a string that is spelled the same way forward and backward. for example, “radar” “madam” “abba” are palindromes, but “car” is not. - Your string should be declared as an array of char.

34

35 Problem #4

Evaluation 36

37 Problem Question Write a program that reads an array of 10 integers from the user, and then find the sum of the numbers that divisible by 3.

38

39