Question

ILS thE Sum of 3- m divided by the quantity m 4. (8 Points) Consider the following fragment and determine its output: #include <iostream> #include <string> using namespace std: Assume the function prototype is given int main() int í. 4, j 6, k = 9; string st abcde fghijklmnopgrstuvwxyz cout << st.find (abcdef) <<* func (i, i, k) 13-3 1: -5 cout << st[?] << endl; // OMG..what does this do? ???? return 0 ) I end of main program void func(int &a, int b, int &c) a c + 2*b; s run. Choose the correct output after the program above i A) 0*22* 6-8 e B) 0*21 6*+9*f C) 0*20*6*-9*g D) 0*21 6*-9*f E) 0*21 6*-8 g
0 0
Add a comment Improve this question Transcribed image text
Answer #1

it is needed to oberve that the given program is in c++ 98 syntax which is a little different from trubo c++.so there's a slight chane in statements and function usage that you need to observe and this explanation is done by ignoring some program ststements in comment section (don't know why they're ommited..may be purposefully to deviate or something i don't know !)

and here's the program  


#include<iostream>
#include<string>
using namespace std;

void func(int,int,int); //prototype of the user defined function

int main()
{
int i=4,j=6,k=9;
string st[]="abcdefghjklmnopqrstuvwxyz";
cout<<st.find("abcdef")<<"*"; // find a sub string
func(i,j,k);
cout<<i<<"*"<<j<<"*"<<k<<"*";
cout<<st[--j]<<endl;
return 0;
}

void func(int &a,int b,int &c)
{
a=c+2*b;
c =-5*b+a;
}

the resulting output of this program is:

0*21*6*-9*f

Explanation

find() function:

this function will find the substring equal to a given character sequence from an existing string

_________________________________________________

the statement

cout<<st.find("abcdef")<<"*";

gives output as

0*

_________________________________________________________________________

now into the statement

func(i,j,k);

will take the execution to its declaration part

void func(int &a,int b,int &c)
{
a=c+2*b;
c =-5*b+a;
}

this function on execution yield the values of a as 21 and c as -9 which are function parameters for i and k repectively. j remains intact during this execution

here "a" and "c" are call by reference parameters and "b" is a call by value parameter

call by value parameters will have access by address location whereas

call by reference parameters will have access by direct values(by variable names)

so the statement

cout<<i<<"*"<<j<<"*"<<k<<"*";

yields the output

21*6*-9*

and finally the following statement

cout<<st[--j]<<endl; // confused?

here " - - j" is very much similar to j= j -1 so it yields the value of j as 5

so replacing the same in the program statement will lok like

cout<<st[5]<<endl; //this looks cool !

now taking this into our mind ,keep an eye on the string st defined as alphabet sequence a through z refering the string as st[0]=a,st[1]=b,st[2]=c,st[3]=d,st[4]=e,.......and so on;

st[5] will yield the ouput "f"

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

the final answer is:

D) 0*21*6*-9*f

Add a comment
Know the answer?
Add Answer to:
ILS thE Sum of 3- m divided by the quantity m 4. (8 Points) Consider the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Transform the find function of Question 4 into a function template. Here is the program used...

    Transform the find function of Question 4 into a function template. Here is the program used to test your template, followed by the output of that program: #include <iostream> #include <string> #include "find.h" using namespace std; #define NUM_ELEMENTS(a) (sizeof(a) / sizeof(a[0])) int main() {         cout << "int" << endl;         cout << "---" << endl;         int arr1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};         cout << "3 is at location " << find(arr1, NUM_ELEMENTS(arr1),...

  • Consider the following C++ program: #include <iostream> #include <cstdlib> using namespace std; int main int n...

    Consider the following C++ program: #include <iostream> #include <cstdlib> using namespace std; int main int n =0; int i = 0; cout << "Please enter a strictly positive number:"; cin >> n if (n <= 0) exit(EXIT_FAILURE) while (n > 1) n-n/2; i << endl; cout"Output:" return 0; Answer the following questions: What is the output of the program for each of the following values of n: -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9? What does...

  • C++ problem. Please just find and fix the errors and highlight it afterwards. Do not add...

    C++ problem. Please just find and fix the errors and highlight it afterwards. Do not add any new comments or remove comments from teachers. Thank you very much *R 2B PROGRAM 1B: INSERTION SORT Find and rix errors. Ron the program once and save the outpat as a conment at the end of the source file Changed by: IDE #include <iostream> using namespace std: void insertionSort (int aryll, int size) int main double list(1001-(50.1, 30.2, 80.3, 10.5, 30.2, 40.9, 90.8,...

  • C++ 4. (5 points) Identify the following items in the programming code shown below: a. Function...

    C++ 4. (5 points) Identify the following items in the programming code shown below: a. Function prototype, function heading, function body, and function definitions. b. Function call statements, formal parameters, and actual parameters. C. Value parameters and reference parameters. d. Local variables and global variables. 6. Named constants. #include <iostream> //Line 1 using namespace std; //Line 2 const double NUM = 3.5; //Line 3 int temp; //Line 4 void func(int, doubles, char); //Line 5 int main() int num; double one;...

  • use c++ 2. Make only one change to the program below so that the current output...

    use c++ 2. Make only one change to the program below so that the current output changes to the desired output. Program Current output Desired output include Kio stream> include <strin using namespace std; int main string s1 Hello World" for (int i 0 i sl. size i++) for (int j 0 j<i j++) cout cout s1 [i] endl return 0;

  • C++ output 6) What is the exact output of the following program? #include <iostream> using namespace...

    C++ output 6) What is the exact output of the following program? #include <iostream> using namespace stdi void zolo(int &a, int sb) int main int x = 5, y =8; zolo(x,y)i cout << "x " << x << endl ; cout << "y = "" << y << endl ; return o: void zolo(int &a, int &b) int v1 = b + a; ' int v2 = b-a; 3 a=v1;13

  • [10pts] 7) What is the output of the following program? In other words, what is printed...

    [10pts] 7) What is the output of the following program? In other words, what is printed to the screen when you run it? #include <iostream> #include <queue> using namespace std int main) char qu[5] ('a, 'b',c'd','e' queue <char> q int N = 4; char ch for(int í - 0:ì < 5;++1) q.push(qu (]) for (int ǐ 0;i < N;++i) { = ch q.front); q push(ch): q.pop while(!q.emptyO) f cout << q.front ) <<endl; q.pop )

  • #include <iostream> #include <string> using namespace std; int main() { int number; int sum = 0;...

    #include <iostream> #include <string> using namespace std; int main() { int number; int sum = 0; while(true) { cout << "Please enter a number between 1 and 11: "; cin >> number; if (number >= 1 && number <= 11) { cout << number << endl; sum = sum + number; //only add the sum when number is in range: 1-11, so add wthin this if case } else { cout << number << endl; cout << "Out of range;...

  • Subject: Object Oriented Programming (OOP) Please kindly solve the above two questions as soon as possible...

    Subject: Object Oriented Programming (OOP) Please kindly solve the above two questions as soon as possible would be really grateful to a quick solution. would give a thumbs up. Thank you! Q3: Question # 3 [20] Will the following code compile? If it does not, state the errors. If it does compile, write the output. //Function.cpp #include <iostream> using namespace std; void printData (long i) cout<<"In long print Data "«<i<<endl; } void printData(int i) cout<<"In int printData "<<i<<endl; ) void...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT