Quiz 6 and Solutions

Quiz 6 and Solutions - Write a program to get a word from...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Computer Techniques for Electronic Design II (ESE 224) Quiz for chapter 6 Period: 12 minutes Multiple Choices 1. Which of the following statements about array is true? a) If the initializing sequence is shorter than an array, the array length would be shorten to the length of initializing sequence. b) If an array is defined without a size, but with an initialization sequence, then the array size is arbitrary. c) An array is a collection of elements of same data type which are stored in adjacent memory locations. d) In an output statement, all values of a character array would be printed out if we just specify the identifier of the array without an offset. ( \0 and characters are that won t be displayed.) e) Integer expressions may be used as array offset. Memory Snapshot Problem 2. int x[5] = {4, 2, 1, 2, 3}; for(int k = 0; k < 5; k++) x[x[k]] = x[k]; What are the value of x[] after the loop execution? Programming (Question 4(b) is optional) 3.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Write a program to get a word from the standard input and check whether it is a palindrome (a word can be read the same way in either direction) or not. For example, ‘deed’ and ‘level’ are palindromes, while most of other words are not. (Suppose the maximum length of input words is 10) Solutions 1. C, E 2. X = {4, 2, 2, 2, 4} int X[5] = {4, 2, 1, 2, 3}; X[4] = X[0] = 4; X[2] = X[1] = 2; X[1] = X[2] = 2; X[2] = X[3] = 2; X[4] = X[4] = 4; 3. #include “stdafx.h” #include <iostream> #include <string> using namespace std; #define MAXSIZE 10 // You don ’ t have to use it if use string operation int main() { string word; int i(0), j(0); bool flag = true; cin>>word; j = word.length(); for(i = 0; i < j / 2; i++) { if(word[i] != word[j – i-1]) { flag = false; break; } } if(flag == true) cout << “The entered word is a palindrome” << endl; else cout <<”The entered word is not a palindrome” << endl; return 0; }...
View Full Document

This note was uploaded on 10/23/2011 for the course ECE 224 taught by Professor Wangxin during the Spring '09 term at SUNY Stony Brook.

Page1 / 2

Quiz 6 and Solutions - Write a program to get a word from...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online