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

Info icon This 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.
Image of page 1

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

View Full Document Right Arrow Icon
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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern