Problem Solving with C++ (9th Edition)
9th Edition
ISBN: 9780133591743
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 8.1, Problem 3STE
What (if anything) is wrong with the following code?
char stringVar[] = “Hello”;
strcat(stringVar, “ and Good–bye.”);
cout << stringVar;
Assume that the code is embedded in a complete
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Fix this code please
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
Using namespace std;
//Structure to hold each menu item
Struct Menultem.
{
String name;
Double price;
};
//Function that reads data from file Int getData(struct Menultem menuList[]) {
//Opening file for reading
Fstream fin("menu.txt", ios::in);
Int i=0;
Struct Menultem temp;
//Loop till entire data is processed While(fin.good())
{
//Getting name
Getline(fin, temp.name);
//Reading price
Fin >> temp.price;
Fin.ignore();
//Storing in array
menuList[i] = temp;
i++;
}
//Closing file
Fin.close();
Return i;
}
//Function that displays menu
Void showMenu(struct Menultem menuList[], int cnt)
Int i;
Cout<<"\n Welcome to the Programmers' Cafe \n\n-Today's Menu--------\n";
//Looping over menu and printing to user
For(i=0; i<cnt; i++)
{
//Printing menu item
Cout << fixed << setprecision(2];
Cout << "\n" << right <<setw(3) << (i+1)…
C++
Add a search command that asks the user for a string and finds the first line that contains that string. The search starts at the first line currently displayed and stops at the end of the file. If the string is found, the line that contains it is displayed at the top. In case the user enters a string X that does not occur in the file, the program should print the error message:
ERROR: string "X" was not found.
Attached is the first lines of the .txt file
BASH FLOW CHART:
Create a flow chart to describe an algorithm that takes a text file with format ID,FirstName,Last Name,Street,City and appends a user ID field consisting of a C followed by theemployee ID. For example, the first entries in Lab 2's employees.txt are:0,Douglas L,Eberhard,Addenda Circle,Cornwall1,Elizabeth Sua,Hemauer,Wyatt Way,Peterborough2,Bailey Rae,Lopez,Turnagain Street,Sault Ste. MarieAfter processing, the entries should be:0,Douglas L,Eberhard,Addenda Circle,Cornwall,C01,Elizabeth Sua,Hemauer,Wyatt Way,Peterborough,C12,Bailey Rae,Lopez,Turnagain Street,Sault Ste. Marie,C2
Chapter 8 Solutions
Problem Solving with C++ (9th Edition)
Ch. 8.1 - Prob. 1STECh. 8.1 - What C string will be stored in singingString...Ch. 8.1 - What (if anything) is wrong with the following...Ch. 8.1 - Suppose the function strlen (which returns the...Ch. 8.1 - Prob. 5STECh. 8.1 - How many characters are in each of the following...Ch. 8.1 - Prob. 7STECh. 8.1 - Given the following declaration and initialization...Ch. 8.1 - Given the declaration of a C-string variable,...Ch. 8.1 - Write code using a library function to copy the...
Ch. 8.1 - What string will be output when this code is run?...Ch. 8.1 - Prob. 12STECh. 8.1 - Consider the following code (and assume it is...Ch. 8.1 - Consider the following code (and assume it is...Ch. 8.2 - Consider the following code (and assume that it is...Ch. 8.2 - Prob. 16STECh. 8.2 - Consider the following code: string s1, s2...Ch. 8.2 - What is the output produced by the following code?...Ch. 8.3 - Is the following program legal? If so, what is the...Ch. 8.3 - What is the difference between the size and the...Ch. 8 - Create a C-string variable that contains a name,...Ch. 8 - Prob. 2PCh. 8 - Write a program that inputs a first and last name,...Ch. 8 - Write a function named firstLast2 that takes as...Ch. 8 - Write a function named swapFrontBack that takes as...Ch. 8 - Prob. 6PCh. 8 - Write a program that inputs two string variables,...Ch. 8 - Solution to Programming Project 8.1 Write a...Ch. 8 - Write a program that will read in a line of text...Ch. 8 - Give the function definition for the function with...Ch. 8 - Write a program that reads a persons name in the...Ch. 8 - Write a program that reads in a line of text and...Ch. 8 - Write a program that reads in a line of text and...Ch. 8 - Write a program that can be used to train the user...Ch. 8 - Write a sorting function that is similar to...Ch. 8 - Redo Programming Project 6 from Chapter 7, but...Ch. 8 - Redo Programming Project 5 from Chapter 7, but...Ch. 8 - Prob. 11PPCh. 8 - Write a program that inputs a time from the...Ch. 8 - Solution to Programming Project 8.14 Given the...Ch. 8 - Write a function that determines if two strings...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Fill in the blanks in each of the following: Each class declaration that begins with keyword must be stored in ...
Java How To Program (Early Objects)
For each of the following activities, give a PEAS description of the task environment and characterize it in te...
Artificial Intelligence: A Modern Approach
Define each of the following terms: entity type entity-relationship model entity instance Attribute relationshi...
Modern Database Management
Write code that will fill the following array a with numbers typed at the keyboard: int [][] a = new int [4][5]...
Java: An Introduction to Problem Solving and Programming (8th Edition)
What is the type or types of the variable(s) that can reference the object created in the following statement? ...
Java: An Introduction to Problem Solving and Programming (7th Edition)
How would the following strings be converted by the CDec function? a. 48.5000 b. 34.95 c. 2,300 d. Twelve
Starting Out With Visual Basic (8th Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Body Mass Index Write a program that reads names, weights, and heights from bmi.dat (provided with starter code; do not change the file name). Use the information to calculate and displays a person’s body mass index (BMI). The BMI is often used to determine whether a person with a sedentary lifestyle is overweight or underweight for his or her height. A person’s BMI is calculated with the following formula: BMI = weight × 703 / height2 where weight is measured in pounds and height is measured in inches. The file is in the format name weightInKG heightInCM You will read the name, weight and height for 4 people from the file, and you will need to convert the weights in the file to pounds (note that 1 kilogram = 2.2 pounds) and the heights to inches (2.54 cm = 1 inch). The program should display the person's name along with the calculated BMI and a message indicating whether the person has optimal weight, is underweight, or is overweight. Your output should look like A person’s weight…arrow_forwardProblem description: Write a python application to simulate an Amazon online book shoppingsystem, namely “Amazing”. Design solution: The template file contains a list of books sold on Amazing, each item in the listcontains the title, publication year, author and the prices. The program will generate anitems_dict where each key is the title of the book and the values will be a list of year, authorand price information. A customer will be presented with a main menu with 4 different options:display all items, add an item to cart, checkout and exit the program. A customer can buy anitem by entering the title of the book. This program implements a dictionary called cart, whereeach key is the title and the values are the list of year, author and price and We assume onecopy is added with each selection. The program keeps repeating by displaying the main menuto user until user hits the quit button. If user hits the checkout option, the program will displayall the items in the cart and display…arrow_forward#include <fstream> #include <iostream> using namespace std; // PLACE YOUR NAME HERE const int MAXNAME = 20; int main() { ifstream inData; inData.open("grades.txt"); char name[MAXNAME + 1]; // holds student name float average; // holds student average inData.get(name,MAXNAME+1); while (inData){ inData >> average; // Fill in the code to print out name and // student average // Fill in the code to complete the while // loop so that the rest of the student // names and average are read in properly } return 0; }arrow_forward
- IN C PROGRAMMING!!! Follow the prompt in the picture and make sure output matches example.arrow_forwardPhython: Create a function so that when giving you a month it tells you the season of that month, for example: if it is January it will be winter.Using the def, try and except ValueError functions.arrow_forward>> classicVinyls.cpp For the following program, you will use the text file called “vinyls.txt” attached to this assignment. The file stores information about a collection of classic vinyls. The records in the file are like the ones on the following sample: Led_Zeppelin Led_Zeppelin 1969 1000.00 The_Prettiest_Star David_Bowie 1973 2000.00 Speedway Elvis_Presley 1968 5000.00 Spirit_in_the_Night Bruce_Springsteen 1973 5000.00 … Write a declaration for a structure named vinylRec that is to be used to store the records for the classic collection system. The fields in the record should include a title (string), an artist (string), the yearReleased (int), and an estimatedPrice(double). Create the following…arrow_forward
- C++ formatting please Write a program (not a function) that reads from a file named "data.csv". This file consists of a list of countries and gold medals they have won in various Olympic events. Write to standard out, the top 5 countries with the most gold medals. You can assume there will be no ties. Expected Output: 1: United States with 1022 gold medals 2: Soviet Union with 440 gold medals 3: Germany with 275 gold medals 4: Great Britain with 263 gold medals 5: China with 227 gold medalsarrow_forwardFile redirection allows you to redirect standard input (keyboard) and instead read from a file specified at the command prompt. It requires the use of the < operator (e.g. java MyProgram < input_file.txt) True or Falsearrow_forwardFinish this program from the code posted below! Note: There should be two files Main.py and Contact.py You will implement the edit_contact function. In the function, do the following: Ask the user to enter the name of the contact they want to edit. If the contact exists, in a loop, give them the following choices Remove one of the phone numbers from that Contact. Add a phone number to that Contact. Change that Contact's email address. Change that Contact's name (if they do this, you will have to remove the key/value pair from the dictionary and re-add it, since the key is the contact’s name. Use the dictionary's pop method for this!) Stop editing the Contact Once the user is finished making changes to the Contact, the function should return. Code:from Contact import Contactimport pickledef load_contacts():""" Unpickle the data on mydata.dat and save it to a dictionaryReturn an empty dictionary if the file doesn't exist """try:with open("mydata.dat", 'rb') as file:return…arrow_forward
- Please help me with this lab senario.arrow_forwardC++HurdleWords The HurdleWords class is mostly provided to you. HurdleWords is constructed from two files in the data/ folder: ● valid_guesses.txt (all 5 letter guesses considered to be valid words to guess), and ● valid_hurdles.txt (all words that may be selected to be the secret Hurdle.) ● Note: you may edit both text files if you’d like to add custom words to your game. HurdleWords stores all potential valid Hurdles from valid_hurdles.txt into a vector of strings (valid_hurdles_), and all valid guesses from valid_guesses.txt into an unordered set of strings (valid_guesses_). A set is simply a data structure that contains no duplicates and allows for a speedy lookup to check if a given element exists within the set. Because there are over 10,000 valid guesses, we store them in an unordered set to leverage their speediness, as you will need to check if a user-submitted guess is considered valid (i.e. their guess is considered a valid guess in the dictionary). You are responsible for…arrow_forwardProblem Definition You are provided with a text file (employees.txt) containing a number of text lines. Each line contains a record of one employee. Each record has three attributes: Title: string, Prof. (Professor) or Dr. (Doctor). First and Last names: string. Salary: float number. The attributes are separated by the character (',). Figure 1.a, 1.b, and 1.c show a sample of employees.txt files. Dr., Julia Scott, 141518 Dr., Julia Scott, 141518 Prof.,Joan Stewart, 111673 Mr.,Ali Al-shukaili,122311 Prof., Sana Al-Abri, 131673 Prof.,Joan Stewart Dr., Fadi A1-Rasdhi, 153790 Ms., Salwa Al-Youssfi, 111675 Dr., Daniel Cooper, 153790 Dr., Lillian Brown, unknown Dr. :Benjamin Russell:117642 Dr., Daniel Cooper, 153790 Dr., Lillian Brown, 67251 Dr., Benjamin Russell,117642 Prof., Patrick Bailey, 72305 Dr., Ralph Flores, 118457 Dr., Douglas Flores, 181793 Dr., Lillian Brown, 67251 Figure 1.b: A sample of the text file 'employees.txt" Figure 1.a: A sample of the text file 'employees.txt' without…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended 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 Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
C - File I/O; Author: Tutorials Point (India) Ltd.;https://www.youtube.com/watch?v=cEfuwpbGi1k;License: Standard YouTube License, CC-BY
file handling functions in c | fprintf, fscanf, fread, fwrite |; Author: Education 4u;https://www.youtube.com/watch?v=aqeXS1bJihA;License: Standard Youtube License