Concept explainers
Explanation of Solution
Modified code:
The modified code for given display 18.17 is shown below:
//Header file
#include <iostream>
#include <list>
#include <algorithm>
//std namespace
using std::cin;
using std::cout;
using std::endl;
using std::list;
using std::find;
//Min function
int main( )
{
/* Declare line in "list" template */
list<char> line;
/* Display prompt statement */
cout << "Enter a line of text:\n";
//Declare variable for "next"
char next;
/* Read text from user */
cin.get(next);
/* If "next" is not equal to "\n" */
while (next != '\n')
{
/* Insert the character to list */
line.push_back(next);
/* Read the next character */
cin.get(next);
}
/* Declare char varaible "where" in constant iterator */
list<char>::const_iterator where;
/* where is located at the first occurrence of 'e' in line.*/
where = find(line.begin( ), line.end( ), 'e');
/* Declare char variable "p" in constant iterator */
list<char>::const_iterator p;
/* Display statement */
cout << "You entered the following before you entered your first e:\n";
/* Using "for" loop, display located at the first occurrence of 'e' in line */
for (p = line...
Want to see the full answer?
Check out a sample textbook solutionChapter 18 Solutions
Problem Solving with C++ (9th Edition)
- Using JavaScriptDefine a function getMonth which accepts number from 1 to 12 as an argument and return the descriptive name of the month. For example: getMonth(1) should return January while getMonth(12) returns December, finally getMonth(-1) returns null. Use array or object to define a list of names for the month and refrain from using if statement to check the argument if it's 1, 2, etc.arrow_forwardAdd the function min as an abstract function to the class arrayListType to return the smallest element of the list. Also, write the definition of the function min in the class unorderedArrayListType and write a program to test this function. I have 5 tabs: I have tried every solution I can think of with no luck. These are the guides: arrayListType.h arrayListTypeImp.cpp: main.cpp unorderedArraryListType.h unorderedArrayListTypeImp.cpp I am needing these in order to pass the assignment in Cengage Mindtap, please help with codes for each one if possible.arrow_forwardComplete the function that computes the length of a path that starts with the given Point. The Point structure = point on the plane that is a part of a path. The structure includes a pointer to the next point on the path, or nullptr if it's the last point. I'm not sure how to fill in the '?'; especially the while loop I'm not sure how to implement the condition for that.arrow_forward
- import numpy as np import torch import matplotlib.pyplot as plt Quiz Preparation Question 1. Write a function that generates a random tensor of n x n (n is the input). The output is the mean of the tensor. = 2, 4, 8, 16, ... 1024 and generate a vector 2. Write a code (for loop) that call that calls the function above with n = M(n). Plot the vector as a function of the log of n. 3. Given an n x m array write a code that replaces every element that is larger than 0.5 with 0.5. 4. The second derivative of a function can be approximated by the finite difference 1 ƒ"(x₂) = 73 (ƒ(£;+1) — 2ƒ(x;) + f(x;-1)) Given a vector f with values f = [f(xo),..., f(n) write a code that computes the approximation to f"(x) 5. The power method is a method to compute the largest eigenvalue of a matrix. Your google search is using this method every time you perform a google search. The method consists of the iteration Vj+1 = Av; || Avi|| where v; is a vector with chosen as a random vector, and A is the matrix…arrow_forwardThere are two tasks to this assignment. Task 1 Currently you are using composition by creating an instance of a vector / ArrayList inside your AddressBook. This works fine but if we really think about it, an AddressBook is a collection like a stack or a queue or a vector for that matter. Your task is to: C++ derive AddressBook from vector. In other words, use the vector as a base class and derive AddressBook from it. This means that you will need to remove the Vector from the private section of your class. Java derive AddressBook from ArrayList. In other words, use the ArrayList as a base class and derive AddressBook from it. This means that you will need to remove the ArrayList from the private section of your class. You are going to have to make some fundamental changes to your AddressBook so that you are using the vector / ArrayList functionality to store and retrieve people. In other words, you should be accessing the ArrayList / vector using this. C++ people, don’t forget you…arrow_forwardComplete the drawTriangle() function in script.js that draws a triangle with asterisks (*) based on the triangleSize parameter. Ex: drawTriangle(4) outputs to the console a triangle with triangleSize 4, so the longest side (4 asterisks) appears on the bottom line: * ** *** **** Hint: Use a loop inside a loop to complete drawTriangle(). The outer loop is responsible for outputting each asterisk line, and the inner loop is responsible for building the asterisk line with the appropriate length by concatenating asterisks to a single string. To test the JavaScript in your web browser, call drawTriangle() from the JavaScript console.arrow_forward
- Create a vector v = (15.9,21.4,19.9,21.9,20.0,16.5,17.9,17.5). What is the smallest valuc inv? What is the largest value? How many are greater than 18? Make a new vector with only those bigger than 18.arrow_forwardHelp with c++... please paste indented code plzz and keep output same as givenarrow_forwardCould you correct the errorarrow_forward
- Please use C++, send screenshot of code running. Because this is the 2nd time I upload this photo, last answer I got, the code wasn’t compiled and run.arrow_forwarda) Can you develop Java code.Create a recursive function to print all permutations of a string. For example, the permutation of the string "abc" is [abc, acb, bac, bca, cab, cba]. b) Revise the genericStack class to use an array instead of an ArrayList. Before adding a new element, make sure the array size is correct. If the current array is full, construct a new array twice the size, copy the elements, and add the new array. dont use aiarrow_forwardmergeAndRemove(int[], int[]) This is a public static function that takes a int[] and int[] for the parameters and returns an int[]. Given two arrays of integers. Your job is to combine them into a single array and remove any duplicates, finally return the merged array.arrow_forward
- 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