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

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...
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...
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 =...
c++ Exercise 1: Make a struct “Fate” that contains the following variables: int month, int year,...
c++ Exercise 1: Make a struct “Fate” that contains the following variables: int month, int year, int day. Make another struct Product that would contain the following variables: 1- Product name. 2- An array for the product ingredients. Set its max size to 3. 3- Product date of expiration. Use the date struct you made. Use those structs in entering the data for two products of your choice. Make a function printProduct(Product product) that prints out the contents of the...
Consider the following struct that represents a node within a binary tree: struct Node { int...
Consider the following struct that represents a node within a binary tree: struct Node { int data; // Data of interest Node *left // Link to left subtree (nullptr if none) Node *right ; // Link to right subtree (nullptr if none) }; Complete the following function that computes the number of elements in a binary tree: // Counts the number of elements in the binary tree to which t points. // Returns the number of elements. int size(Node *t)...
Translate the following function f to MIPS assembly code. int f(int a, int b, int c,...
Translate the following function f to MIPS assembly code. int f(int a, int b, int c, int d) { return func(func(a,b), func(b+c,d)); } Assume the followings. • The prototype of function func is “int func(int a, int b);”. • You do not need to implement function func. The first instruction in function func is labeled “FUNC”. • In the implementation of function f, if you need to use registers $t0 through $t7, use the lower-numbered registers first. • In the...
What is the ouput of the following code? void loop(int num) { for(int i = 1;...
What is the ouput of the following code? void loop(int num) { for(int i = 1; i < num; ++i) { for(int j = 0; j < 5; ++j) { cout << j; } } } int main() { loop(3); return 0; }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT