Structures

1

Which of the following accesses a variable in structure *b?

A. b->var;
B. b.var;
C. b-var;
D. b>var;

2

Which of the following is a properly defined structure?

A. struct {int a;}
B. struct a_struct {int a;}
C. struct a_struct int a;
D. struct a_struct {int a;};

3

What is the output of this program?

 
1.
    #include 
2.    
    using namespace std;
3.    
    struct sec {
4.    
        int a;
5.        
        char b;
6.        
    };
7.    
    int main()
8.    
    {
9.    
        struct sec s ={25,50};
10.        
        struct sec *ps =(struct sec *)&s;
11.        
        cout << ps->a << ps->b;
12.        
        return 0;
13.        
    }
A. 252
B. 253
C. 254
D. 262

4

What will be the output of this program?

1.
    #include 
2.    
    using namespace std;
3.    
    int main()
4.    
    {
5.    
        struct ShoeType {
6.        
           string style;
7.           
           double price;
8.           
        };
9.        
         ShoeType shoe1, shoe2;
10.         
         shoe1.style = "Adidas";
11.         
         shoe1.price = 9.99;
12.         
         cout << shoe1.style << " $ "<<          
         shoe1.price;
13.         
         shoe2 = shoe1;
14.         
         shoe2.price = shoe2.price / 9;
15.         
         cout << shoe2.style << " $ "<< 
         shoe2.price;
16.         
         return 0;
17.         
    }
A. Adidas $ 9.99 Adidas $ 1.11
B. Adidas $ 9.99 Adidas $ 9.11
C. Adidas $ 9.99 Adidas $ 11.11
D. none of the mentioned

5

What is the output of this program?

1.
    #include 
2.
    using namespace std;
3.    
    struct Time {
4.    
        int hours;
5.        
        int minutes;
6.        
        int seconds;
7.        
    };
8.    
    int toSeconds(Time now);
9.    
    int main()
10.    
    {
11.    
        Time t;
12.        
        t.hours = 5;
13.        
        t.minutes = 30;
14.        
        t.seconds = 45;
15.        
        cout << "Total seconds: " << toSeconds(t) << endl;
16.        
        return 0;
17.        
    }
18.    
    int toSeconds(Time now)
19.    
    {
20.    
        return 3600 * now.hours + 60 * now.minutes + now.seconds;
21.        
    }
A. 19845
B. 20000
C. 15000
D. 19844