EBK C++ PROGRAMMING: PROGRAM DESIGN INC
8th Edition
ISBN: 9781337669085
Author: Malik
Publisher: VST
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
В.width; }
{ t = B.type; w =
{ T.type = C.type; T.width = C.width; }
T → B
C
В > int
{ B.type = integer; B.width
4; }
В — foat
{ B.type = float; B.width =
8; }
{ C.type = t; C.width
= w; }
C - [ num] C1 = array(num. value, C1.type);
{ C.type
C.width
= num. value x C1. width; }
a) FindMinIterative
public int FindMin(int[] arr) { int x = arr[0]; for(int i = 1; i < arr.Length; i++) { if(arr[i]< x) x = arr[i];
} return x; }
b) FindMinRecursive
public int FindMin(int[] arr, int length) { if(length == 1) return arr[0];
return Math.Min(arr[length - 1], Find(arr, length - 1));
}
What is the Big-O for this functions. Could you explain the recurisive more in details ?
Note: 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.
Chapter 8 Solutions
EBK C++ PROGRAMMING: PROGRAM DESIGN INC
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
- A/ find code optimization method to this code and then find type to this code 1- For(i=1;iarrow_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_forwardin c++ language pleasssearrow_forward#include using namespace std; main () { int array [8] for (int x=; x> for ( cout<< return ; X< : ) : }arrow_forwardIn C++ Syntax for arrays of objects classGrades allCS[15]; //the default constructor is applied to //all elements of this array //to set the number of students in each class to 25 for (i = 0; i < 15; i++) { allCS[i].setNumStudents(25); } //Assume values in all classes. Write the code to print all class averages?arrow_forwardC++ Programming, Arrays Lights The park is illuminated by n (1 < n < 100) lights. Each of them shines all night or not. Of course, which lights were on the first night and which were not. Every other night the condition of the lamps shall be determined by the following rules: the lamp will not illuminate if both of its neighbors were lit last night; the lamp shall illuminate if one of its neighbors was illuminated last night and the other was not; if neither of the first two rules applies to the lamp, it will illuminate when the night is even and will not illuminate when the night is odd. Create a program to determine which lights are on and which will not be lit when k (1 < k < 100) nights have elapsed, and to find which night the most lights were lit and which the least. If there are several identical nights with the most or least lights lit, the night with the lower number must be indicated. The first line of the original data file contains two integers: the number of…arrow_forwardC++ ProgrammingActivity: Deque Linked List Explain the flow of the code not necessarily every line, as long as you explain what the important parts of the code do. The code is already correct, just explain the flow. #include "deque.h" #include "linkedlist.h" #include <iostream> using namespace std; class DLLDeque : public Deque { DoublyLinkedList* list; public: DLLDeque() { list = new DoublyLinkedList(); } void addFirst(int e) { list->addAt(e,1); } void addLast(int e) { list->addAt(e,size()+1); } int removeFirst() { return list->removeAt(1); } int removeLast() { return list->removeAt(size()); } int size(){ return list->size(); } bool isEmpty() { return list->isEmpty(); } // OPTIONAL: a helper method to help you debug void print() {…arrow_forwardC CodeApproved Libraries:<string.h> *not allowed in some questions<math.h><stdlib.h><time.h> (for srand(time(0)) only)arrow_forwardThis C++ program keeps giving me the wrong median. #include <iostream> using namespace std; double median_value(int* arrptr, int n); class Median { private: int* array; int n; public: void getSizeArray(); void getNumElements(); void displayMedian(); ~Median() { delete[] array; } }; void Median::getSizeArray() { cout << "How big is array?"; cin >> n; } void Median::getNumElements() { array = new int[20]; for (int i = 0; i < n; i++) { cout << "How much "; cin >> *(array + i); } } void Median::displayMedian() { int m = median_value(array, n); cout << m; } int main() { Median showMedian; showMedian.getSizeArray(); showMedian.getNumElements(); showMedian.displayMedian(); return 0; } double median_value(int* arrptr, int n) { double median; if (n % 2 == 0) { median = (*(arrptr + (n / 2)) + *(arrptr + (n / 2 +1))) / 2; } else { //(arrptr[i]+(n/2)) median = *(arrptr + (n / 2)); } return median; }arrow_forwardWhat benefits do enumeration types provide over a collection of named constants? What benefits does a subrange type have over its base type? When might a string be preferable over a character array?arrow_forward#include <iostream>#include <vector>using namespace std; void PrintVectors(vector<int> numsList) { unsigned int i; for (i = 0; i < numsList.size(); ++i) { cout << numsList.at(i) << " "; } cout << endl;} int main() { vector<int> numsList; int userInput; int i; for (i = 0; i < 3; ++i) { cin >> userInput; numsList.push_back(userInput); } numsList.erase(numsList.begin()+1); numsList.insert(numsList.begin()+1, 102); numsList.insert(numsList.begin()+1, 100); PrintVectors(numsList); return 0;} Not all tests passed clearTesting with inputs: 33 200 10 Output differs. See highlights below. Special character legend Your output 33 100 102 10 Expected output 100 33 102 10 clearTesting with inputs: 6 7 8 Output differs. See highlights below. Special character legend Your output 6 100 102 8 Expected output 100 6 102 8 Not sure what I did wrong but the the 33…arrow_forward#include <iostream> using namespace std; const int ROWS = 10; const int COLS = 10; int generateRND(int MIN, int MAX) { return rand() % (MAX - MIN + 1) + MIN; } void initializeArray(int C[][COLS], int min, int max) { for (size_t i = 0; i < ROWS; i++) { for (size_t j = 0; j < COLS; j++) { C[i][j] = generateRND(min, max); } } } void swap(int A[][COLS], int B[][COLS]) { int temp; for (size_t j = 0; j < COLS; j += 2) { for (size_t j = 0 ; j< COLS; j +=) } } void printArray(int C[][COLS]) { for (size_t i = 0; i < ROWS; i++) { for (size_t j = 0; j < COLS; j++) { cout << C[i][j] << " "; } cout << endl; } } int main() { srand((unsigned)time(0)); int A[ROWS][COLS] = { 0 }; int B[ROWS][COLS] = { 0 }; const int MIN = 2; const int MAX = 50; initializeArray(A, 2, 50); } Declares two 10X10 Two-dimensional arrays A and B of type integer. Each array consists of 100 random integers between 2 and 50. 1. Swaps (exchange) the elements of A with…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