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++, Student Value Edition plus MyProgrammingLab with Pearson eText -- Access Card Package (9th Edition)
- please complete the following in JAVA Implement the graph ADT using the adjacency list structure. thanks! also posting a similar question for adjacency matrix. have a good day!arrow_forward1. Write a Java program that would resemble banking transactions of deposits, withdrawals, bank to bank transfers, and interest computations. A transaction input window is to be used in entering the account number, transaction code, and amount. Search a 2d-ArrayList containing the account number and the current balance, and then do the appropriate update on the 2d-ArrayList depending on the transaction code. If the transaction code is “D”, update the current balance by adding the amount; if “W”, update the current balance by subtracting the amount from the current balance provided that a withdrawal transaction is allowed (current balance must be greater than the amount to be withdrawn, and the resulting balance must not be less than 500). Display the updated 2d-ArrayList before exiting the program. (USE OOP CONCEPT JFRAME)arrow_forwardAdd a constructor initializer list to the overloaded constructor Professor(string newName, int newStudents) to initialize name with newName and students with a vector of size given by newStudents. Ex: If the input is Jan 2 Ava Ada, then the output is: Professor: Unknown, No students Professor: Jan, Students: Ava, Ada #include <iostream>#include <vector>using namespace std; class Professor {public:Professor();Professor(string newName, int newStudents);void ReadStudents();void Print() const;private:string name;vector<string> students;}; Professor::Professor() : name("Unknown"), students(0) {} Professor::Professor(string newName, int newStudents) /* Your code goes here */ {} void Professor::ReadStudents() {string studentName;int i;for (i = 0; i < students.size(); ++i) {cin >> studentName; students.at(i) = studentName;}} void Professor::Print() const {int i; cout << "Professor: " << name << ", ";if (students.size() == 0) {cout <<…arrow_forward
- Distinguish between an array and an arraylist and describe their primary distinctions.arrow_forwardWrite a C++ program define a vector object and initialize it with 3 values and then define an iterator that points to elements of this object, then ask the user to enter 3 more values and then add them to the previous vector and then print all elements in the vector.arrow_forwardIn java Define and create an array with these values using an initializer list: 9, 18, 3, 0, 12 and replace the second element with the value 99. Print the elements of the array from the last element to the firstarrow_forward
- Java code 8. Given an existing ArrayList named friendList, find the first index of a friend named Sasha and store it in a new variable named index.arrow_forwardImplement code to shows a linear array where the size is specified in the constructor. Elements are accessed with the [] operator. An error check for index out of range is added.arrow_forwardWhat would be a way in implementing the Josephus problem in C++ using a vector or a list? That takes in three parameters, one the number of knights for the knight parameter. The second parameter, "skip", is the number of knights to skip and to execute the next night. Then the third parameter "start", is the index of the knight to execute first.arrow_forward
- Add 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_forwardIn C++, declare a map <int,Student> to store serial number and student object. Student class contain id, name and cgpa. Print all map data.arrow_forwardWrite a class TouristSpot that has the data members; name of tourist spot, state in which it lies. Create an array list of n places and write a function that takes array list as an argument to identify a state that has more than one tourist spot. Java Programarrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning