Loading
submit to reddit
May 18, 2013, 04:41:37 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Welcome!
 
   Forum Home   Help Search Forum Login Register  
Pages: [1]   Go Down
  Send this topic  |  Print  
Author Topic: Please help me answer some c++ questions.  (Read 413 times)
thenewbiecoder
Newbie
*
Posts: 1


« on: November 11, 2011, 10:42:14 PM »

I have a few questions to answer before my exam, if anyone can help.

1. Given the code segment:
enum Flowers{ROSE,DAFFODIL,LILY,VIOLET,COSMOS…
Flowers choice;
choice = LILY;
choice++;
why does the compiler give an invalid type error message for the last line?

2. Given the following declarations
struct Name
{
string first;
string middle;
string last;
};
Name yourName;
Name myName;

What are the contents of the two Name variables after each of the following statements, assuming they are executed in the order listed?
a. yourName.first="George";
b. yourName.last="Smith";
c. myName = yourName;
d. myName.middle="Nathaniel";
e. yourName.middle=myName.middle.at(0)+".";

3. Given the following union declarations:
union GradeUnion
{
char gradeLetter;
int gradeNumber;
}
GradeUnion grade;
what does each of the following statements do, assuming they are executed in the order shown?
a. cin>>grade.gradeLetter;
b. if(grade.gradeLetter >= 'A' && grade.gradeLetter <= 'D'
c. grade.gradeNumber = 4-int(grade.gradeLetter = 'A');

4. How many elements are there in each of the following arrays?
a. int x[27];
b. const int base = 10;
int y[base+5];
c. int z[100][100][100][100];

5. What's wrong with the following code segment?
int prep[100];
for (int index=1;index<=100;index++)
prep[index]=0;

6. What's wrong with the following code segment?
const int limit =100;
int eprep[limit];
int examp[limit];
for(int index=0;index<=limit-1;index++)
{
eprep[index]=0;
examp[index]=0;
}
if(eprep==examp)
cout << "Equal";

7. What's the potential danger in the following code segment?
int index;
int value;
int xeperp[100];
cin >> index >> value;
xeperp[index] = value;
Logged
Pages: [1]   Go Up
  Send this topic  |  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!