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++;...
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...
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 piece of Java code? int id = 4; double...
What is the output of the following piece of Java code? int id = 4; double grossPay = 81.475; String jobType = "Intern"; System.out.printf("Id: %d, Type: %s, Amount:%.2f", id,grossPay,jobType); Select one: Error Id: 4, Type: Intern, Amount: $81.475 Id: 4, Type: $81.475, Amount: Intern Id: 4, Type: $81.48, Amount:Intern Id: 4, Type: Intern, Amount: $81.48
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; }
consider the code; typedef struct { int size; int *nums; }Data; Complete the function below that...
consider the code; typedef struct { int size; int *nums; }Data; Complete the function below that creates and returns a new data type that contains a nums array with size randomly chosen integers. Ensure proper error checking. Data *getRandomData(int size) { //PUT CODE HERE //Create random ints for(int i=0; i<size; i++) d->nums[1] = (int)(rand()/(float)RAND_MAX*100); return d;
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; }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT