Question

In: Computer Science

1)What is the output of the following code? struct someType { int a; int b; };...

1)What is the output of the following code?
struct someType
{ int a;
int b;
};
void f1(someType &s)
{ s.a = 1;
s.b = 2;
}
someType f2(someType s)
{ someType t;
t = s;
s.a = 3;
return t;
}
int main()
{ someType s1, s2;
f1(s1);
s2 = f2(s1);
cout << s1.a << '-' << s1.b << '-' <<
s2.a << '-' << s2.b << '-' << endl;
return 0;
}

------------------------------------------------------------------------------------------------------------------

2)

struct dateType {
   int month;
   int day;
   int year;
};

struct employeeType {
   string name;
   dateType birthDate;
   dateType hireDate;
};

employeeType emp;
cout << emp.name << endl;
cout << "   Born " << emp.birthDate.month << "-" << emp.birthDate.day << endl;

QUestion --The following code is used to read in the year each employee was hired. What should be placed in the blank to finish the code?

// Use structures declared above
employeeType employees[10];
for (int i = 0; i < 10; i++)
{
cin >> ___________;
}

Solutions

Expert Solution

Question 1:

Answer :1-2-1-2-

Explanation :

  • here s1.a will print 1 then s1.b will print 2
  • s1 is passed by references in f1() hence changes will be made in the memory and hence
  • s2.a will again print 1 and s2.b will print 2
  • and hence the answer

Below screen shows the output

========================

Question 2:

Screen :

Explanation :Here emp.name will be empty and emp.birthDate.month will be 0 and emp.birthDate.day will be 0

======================

Question 3:

employeeType employees[10];
for (int i = 0; i < 10; i++)
{
cin>>employees[i].hireDate.year;
}


Related Solutions

In c++: Code Challenge Consider the following code: struct ListNode { int value; struct ListNode *next;...
In c++: Code Challenge Consider the following code: struct ListNode { int value; struct ListNode *next; }; ListNode *head; // List head pointer Assume that a linked list has been created and head points to the first node. Write code that traverses the list displaying the contents of each node’s value member Now write the code that destroys the linked list
What is the output of the following C++ code? int* length; int* width; length = new...
What is the output of the following C++ code? int* length; int* width; length = new int; *length = 5; width = length; length = new int; *length = 2 * (*width); cout << *length << " " << *width << " " << (*length) * (*width) << endl;
All QUESTIONS, PLEASE 5.    What is the output of the following code: int product = 1,...
All QUESTIONS, PLEASE 5.    What is the output of the following code: int product = 1, i = 6; while (i < 9) {       product = product * i;       i++; } cout << “i is : ” << i << endl; cout << “product is : ” << product << endl; 6.    What is the output of the following code: int product = 1, i = 6;      do {       product = product * i;       i++;...
Please do this code with python. Thank you! struct Node {     int data;     struct...
Please do this code with python. Thank you! struct Node {     int data;     struct Node* left;     struct Node* right; }; // Node creation struct Node* newNode(int data) {     struct Node* nn         = new Node;     nn->data = data;     nn->left = NULL;     nn->right = NULL;     return nn; } // Function to insert data in BST struct Node* insert(struct Node* root, int data) {   if (root == NULL)         return newNode(data);     else {...
What is the output of the following code: x = 0 a = 1 b =...
What is the output of the following code: x = 0 a = 1 b = -3 if a > 0:    if b < 0:       x = x + 5    elif a > 5:       x = x + 4    else:       x = x + 3 else:     x = x + 2 print(x) 4 2 5 3 Consider the following code segment:    sum = 0.0    while True:       number = input(“Enter a...
Translate the following C code to MIPS assembly. int a = 1; int b = 2;...
Translate the following C code to MIPS assembly. int a = 1; int b = 2; if (a<b)           a=a+1; b = b + a; printf("The value of b is: %d", b); Translate the following C code to MIPS assembly. int a = 2; int b = 2; if (a<b)           a=a+1; else           a=a-1; b = b + a; printf("The value of b is: %d", b);
what is the output? int main ( ) { int a = 3, b= 2, c=...
what is the output? int main ( ) { int a = 3, b= 2, c= 1, d, e, f, g; d = a&b;    e = a | c; f = a >> 1, g = a << 1; cout << “d= “ << d << “ e = “ << e << “ f = “ << f << “g = “ << g << endl; }
The task is to sort structs in array. The struct is struct coor{ int x; int...
The task is to sort structs in array. The struct is struct coor{ int x; int y; int z; }; Create an array with 100 coordinates, which are randomly initiated with x between 0 and 30 and y between 5 and 60, and z between 10 and 90. Then modify the Quick Sort algorithm (QuickSort.cpp) to sort coordinated. Comparison of the coordinates should be carried on first x, then y, and z last. It means that if two points has...
What output is produced by the following code fragment? int num = 0, max = 20;...
What output is produced by the following code fragment? int num = 0, max = 20; while (num < max) { System.out.println(num); num += 4; }
Show the output of the following code segment. int count=0;                         for (int i=2; i <=...
Show the output of the following code segment. int count=0;                         for (int i=2; i <= 4; i++ ) {                                     StdOut.println(i);                                     for (int j=1; j <3; j++) {                                                 count++;                                                 StdOut.println(i +" " + j +" "+ count);                                     }                         } count i j I print 0 2 1 3 1 1 1 2 3 2 2 3 3 3 3 4 3 Show the output of the function call statements shown.             double x =...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT