C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9781337102087
Author: D. S. Malik
Publisher: Cengage Learning
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 8, Problem 10SA
Explanation of Solution
The computations proceed as follows:
myMyList[0] = 2.5
Inside the for loop:
1stiteration:
i = 1
myList[1] = 1 * myList[1-1] = myList[0] = 2.5
2nditeration:
i = 2
myList[2] = 2 * myList[2-1] = 2 * myList[1] = 2 * 2.5 = 5.0
3rditeration:
i = 3
myList[3] = 3 * myList[3-1] = 3 * myList[2] = 3 * 5.0 = 15...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
C++ Code
///////
#include <iostream>
class BTNode {public:int item;BTNode *left;BTNode *right;BTNode(int i, BTNode *l=nullptr, BTNode *r=nullptr):item(i),left(l),right(r){}};
BTNode *root = nullptr;
void insert(int i) {//implement code here}
int main(){insert (5);insert (10);insert (1);if (root){std::cout << "root = " << root->item << std::endl;if (root->left)std::cout << "root->left = " << root->left->item << std::endl;if (root->right)std::cout << "root->right = " << root->right->item << std::endl;}return 0;}
#include <stdio.h>
int arrC[10] = {0};
int bSearch(int arr[], int l, int h, int key);
int *joinArray(int arrA[], int arrB[])
{
int j = 0;
if ((arrB[0] + arrB[4]) % 5 == 0)
{
arrB[0] = 0;
arrB[4] = 0;
}
for (int i = 0; i < 5; i++)
{
arrC[j++] = arrA[i];
if (arrB[i] == 0 || (bSearch(arrA, 0, 5, arrB[i]) != -1))
{
continue;
}
else
arrC[j++] = arrB[i];
}
for (int i = 0; i < j; i++)
{
int temp;
for (int k = i + 1; k < j; k++)
{
if (arrC[i] > arrC[k])
{
temp = arrC[i];
arrC[i] = arrC[k];
arrC[k] = temp;
}
}
}
for (int i = 0; i < j; i++)
{
printf("%d ", arrC[i]);
}
return arrC;
}
int bSearch(int arr[], int l, int h, int key)
{
if (h >= l)
{
int mid = l + (h - l) / 2;
if…
Q1
#include <stdio.h>
int arrC[10] = {0};
int bSearch(int arr[], int l, int h, int key);
int *joinArray(int arrA[], int arrB[])
{
int j = 0;
if ((arrB[0] + arrB[4]) % 5 == 0)
{
arrB[0] = 0;
arrB[4] = 0;
}
for (int i = 0; i < 5; i++)
{
arrC[j++] = arrA[i];
if (arrB[i] == 0 || (bSearch(arrA, 0, 5, arrB[i]) != -1))
{
continue;
}
else
arrC[j++] = arrB[i];
}
for (int i = 0; i < j; i++)
{
int temp;
for (int k = i + 1; k < j; k++)
{
if (arrC[i] > arrC[k])
{
temp = arrC[i];
arrC[i] = arrC[k];
arrC[k] = temp;
}
}
}
for (int i = 0; i < j; i++)
{
printf("%d ", arrC[i]);
}
return arrC;
}
int bSearch(int arr[], int l, int h, int key)
{
if (h >= l)
{
int mid = l + (h - l) / 2;
if…
Chapter 8 Solutions
C++ Programming: From Problem Analysis to Program Design
Ch. 8 - Mark the following statements as true or false. A...Ch. 8 - Consider the following declaration: (1,2) double...Ch. 8 - Identify error(s), if any, in the following array...Ch. 8 - Determine whether the following array declarations...Ch. 8 - Prob. 5SACh. 8 - Write C+ + statement(s) to do the following: (1,...Ch. 8 - Prob. 7SACh. 8 - Prob. 8SACh. 8 - Prob. 9SACh. 8 - Prob. 10SA
Ch. 8 - Prob. 11SACh. 8 - Correct the following code so that it correctly...Ch. 8 - Prob. 13SACh. 8 - Suppose that points is an array of 10 components...Ch. 8 - Determine whether the following array declarations...Ch. 8 - Prob. 17SACh. 8 - Prob. 19SACh. 8 - Prob. 1PECh. 8 - Prob. 2PECh. 8 - Write a C+ + function, lastLargestIndex that takes...Ch. 8 - Write a program that reads a file consisting of...Ch. 8 - Prob. 6PECh. 8 - Write a program that allows the user to enter the...Ch. 8 - Write a program that uses a two-dimensional array...Ch. 8 - Prob. 12PECh. 8 - Write a program to calculate students average test...
Knowledge Booster
Similar questions
- C++ help please my function: bool palindrome(const int a[], int start, int end){ bool flag = true; for (int i = start; i <= end / 2 && a[i]!= 0; i++) { if (a[i] != a[end - i - 1]) { flag = false; cout << "Array Is Not Palindrome\n"; return false; } } if (flag == true) cout << "Palindrome"; return true;} the main: int a[]= {1,2,1,2,1};cout << "Array = [1,2,1,2,1}\n";cout << "Testing array palindrome using 3 parameters:\n";palindrome(a, 2, 3); please help my function is not doing what it is supposed to :( it returns true when its not supposed toarrow_forward#include using namespace std; int main() (double degree [6] [2] = {30,40,10,70, 20, 30, 60, 70, 30, 10, 10, 85); int buffer=degree[0][0]; for (int i=1;ibuffer) buffer=degree[i][0]; cout using namespace std; int main() { int j=1; while (j<=10) if ((j%3)==0) cout<arrow_forwardint X[10]={2,0,6,11,4,5,9,11,-2,-1); From the code above, what is the value of X[8] ?arrow_forwardvoid listEmployees (void) { for (int i=0; i 10000. Make a guess about why the comparison function takes 2 struct Employee parameters (as opposed to struct Employee *) **arrow_forward#include using namespace std; int main() (double degree [6] [2]= (30,40,10,70, 20, 30, 60, 70, 30, 10, 10, 85); int buffer=degree[0][0]; for (int i=1;ibuffer) buffer=degree[i][0]; cout<arrow_forward// Assume all libraries are included void QQ(int n); // int main () { // Random questions QQ (5) ; 3 4 6. 7 8. 9. 10 return 0; 11 } // void QQ(int n) 12 13 14 { if(n >= 1) { 15 16 17 cout << n; QQ (--n); } else 18 19 20 21 cout << n; 22 } // 23arrow_forward: Write a small matrix library The library should have the following functions: double sumOfRow(const double mat[][MAX_COL], const int row, const int maxRow); double sumOfCol(const double mat[][MAX_COL], const int column, const int maxRow); void fillWithRandomNum(double mat[][MAX_COL], const int maxRow); void printMatrix(const double mat[][MAX_COL], const int maxRow);arrow_forwardNote: Code in c++ Consider the following statements: unorderedLinkedList myList; unorderedLinkedList subList; Suppose myList points to the list with elements 34 65 27 89 12 (in this order). The statement: myList.divideMid(subList); divides myList into two sublists: myList points to the list with the elements 34 65 27, and subList points to the sublist with the elements 89 12.arrow_forwardA/ find code optimization method to this code and then find type to this code 1- For(i=1;iarrow_forwardNot allowed to add variables in brackets next to originIndex * @return index of the point that is closest to the origin, which is (0, 0) In * case of a tie, return the lowest index */ public int closestToOriginIndex() {arrow_forwardWhat happens when the ref or out keyword is used with an array parameter?arrow_forward#include using namespace std; class Student { public: void setMarks(){ } double getAV(double a[]){ double sum=0; for(int i=0;i<7;i++) sum-sum+a[i]; return sum/7; double a[]={10, 20, 30, 40, 50, 60, 70); cout<arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_iosRecommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSONC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education