EBK DATA STRUCTURES AND ALGORITHMS IN C
4th Edition
ISBN: 9781285415017
Author: DROZDEK
Publisher: YUZU
expand_more
expand_more
format_list_bulleted
Question
Chapter 5, Problem 4PA
Program Plan Intro
Implementation of a pretty printing program that indents the code in input file.
Program plan:
- Define a function named “main()” to get the file input containing the code and process it using various “if()” conditions.
- Use a “if()” condition to check whether the input file is available or not.
- Use a “while()” loop to iterate till the end of the file and add the input to the array.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a C++ Program using classes, functions (recursive and otherwise), arrays and other C++ commands where a user enters the name of a file and the program calculates the amount of vowels (a,e,i,o,u -lower case and A,E,I,O,U - UPPER CASE, separately!), the letters y, Y, ñ, Ñ, and punctuation marks in the file. You can use the Loren Ipsum generator online for a test file: https://es.lipsum.com/
Write a C Program that takes an input (2 text.txt) files, and counts the number of times the elements of File 1, appear in File 2, and print the result as shown. Please read the example below:
Example:
File A:
BarcelonaDublinLas VegasLisbonLondonMadridNew YorkRioSan FransiscoShanghaiToronto
File B:
BarcalonaMadridMadridMadridMadridSan FransiscoTorontoVancouver
Output after running the C Program using Binary Search Algorithm is:
Barcelona is present 1 time/sDublin is present 0 time/sLas Vegas is present 0 time/sLisbon is present 0 time/sLondon is present 0 time/sMadrid is present 4 time/sNew York is present 0 time/sRio is present 0 time/sSan Fransisco is present 1 time/sShanghai is present 0 time/sToronto is present 1 time/s
Give solution in C ++ Language with secreenshoot of source code. Part 01In this task, you need to do the following:• Write a function named displayMessage() that takes user name as input in character array and then shows greetings• Now take the name input in main() and pass the name as an argument to displayMessage() function• Change the displayMessage() method such that it returns the number of characters after displaying the greetings part 02Write a function power that takes two parameters a and b. And it returns the power as ab.
Chapter 5 Solutions
EBK DATA STRUCTURES AND ALGORITHMS IN C
Ch. 5 - Prob. 1ECh. 5 - Prob. 2ECh. 5 - Prob. 3ECh. 5 - Prob. 4ECh. 5 - Prob. 5ECh. 5 - Prob. 6ECh. 5 - Prob. 7ECh. 5 - Prob. 8ECh. 5 - Prob. 9ECh. 5 - Prob. 10E
Ch. 5 - Prob. 11ECh. 5 - Prob. 12ECh. 5 - Prob. 13ECh. 5 - Prob. 14ECh. 5 - Prob. 15ECh. 5 - Prob. 16ECh. 5 - Prob. 17ECh. 5 - Prob. 18ECh. 5 - Prob. 19ECh. 5 - Prob. 20ECh. 5 - Prob. 21ECh. 5 - Prob. 22ECh. 5 - Prob. 23ECh. 5 - Prob. 24ECh. 5 - Prob. 25ECh. 5 - Prob. 26ECh. 5 - Prob. 27ECh. 5 - Prob. 28ECh. 5 - Prob. 29ECh. 5 - Prob. 1PACh. 5 - Prob. 3PACh. 5 - Prob. 4PACh. 5 - Prob. 5PA
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
- Write a pythonprogram that reads in a Python source code file and counts the occurrence of each keyword and eachidentifier (variables, class and method names) in the file using three dictionaries: one for keywords and one forvariables, and one for integer (e.g. 12,44) and string literals (e.g. “aba”, “ali”) Your program should prompt theuser to enter the Python source code filename.Keywords in Python programming language:False class finally is return None continue for lambda tryTrue def from nonlocal while and del global not with as elifif or yield assert else import pass breakarrow_forwardSuppose you are writing a C++ function that has three alternativeapproaches for accomplishing its requirements. Write a skeletal versionof this function so that if the first alternative raises any exception, thesecond is tried, and if the second alternative raises any exception, thethird is executed. Write the code as if the three methods were proceduresnamed alt1, alt2, and alt3.arrow_forwardWrite a program in C or C++ that converts decimal numbers to binary, hexadecimal, and BCD. You are not allowed to use library functions to do conversion. The output should look as follows. Send the output to a file and upload it along with your source file. DECIMAL BINARY HEXDECIMAL BCD 0 0000 0000 00 0000 0000 0000 1 0000 0001 01 0000 0000 0001 2 0000 0010 02 0000 0000 0010 . . . . . . . . 255 1111 1111 FF 0010 0101 0101arrow_forward
- Write a program in C++ that finds the count of a number in a list of integers from a text file named input.txt. - The output will be written to ouput.txt and will count up to the largest number in the list and display how many times each number appears. - The program must first check if input.txt exists. - The maximum /minimum and total amount will be displayed. - You must use functions (the more functions you use, the easier it will be to debug). - Add comments to your code thoroughly explaining the logic. - Libraries you may use: #include <iostream>, #include <string>, #include <fstream>, #include <iomanip>, #include <cmath>, #include <vector>, #include <ctime> - You may use vectors, arrays, and searching & sorting methods Ex: input.txt has: 3, 4, 3, 7, 1, 7, 3, 6 output.txt has: 1: * (1) //asterisks show how many times the number appears 2: (0) //columns must be aligned 3: *** (3) 4: * (1) 5: (0) 6: * (1) 7: ** (2) Max: 7 Min:1 There are…arrow_forwardWrite a program in C++ that finds the count of a number in a list of integers from a text file named input.txt. - The output will be written to ouput.txt and will count up to the largest number in the list and display how many times each number appears. - The program must first check if input.txt exists. - The maximum /minimum and total amount will be displayed. - You must use functions (the more functions you use, the easier it will be to debug). - Add comments to your code thoroughly explaining the logic. - Libraries you may use: #include <iostream>, #include <string>, #include <fstream>, #include <iomanip>, #include <cmath>, #include <vector>, #include <ctime> - You may use vectors, arrays, and searching & sorting methods Ex:arrow_forwardWrite a program in C++ that reads HAND_SIZE cards from the user, then analyzes the cards and prints out the type of poker hand that they represent. (HAND_SIZE will be a global constant, typically 5, but your program must still work if it is set to something other than 5.) Poker hands are categorized according to the following hand-types: Straight flush, four of a kind, full house, straight, flush, three of a kind, two pairs, pair, high card. To simplify the program we will ignore card suits, and face cards. The values that the user inputs will be integer values from LOWEST_NUM to HIGHEST_NUM. (These will be global constants. We'll use LOWEST_NUM = 2 and HIGHEST_NUM = 9, but your program must work if these are set to something different.) When your program runs it should start by collecting HAND_SIZE integer values from the user and placing the integers into an array that has HAND_SIZE elements. It might look like this: Enter 5 numeric cards, no face cards. Use 2 - 9. Card 1: 8 Card 2:…arrow_forward
- In the C program, I am trying to create a function that will separate a string by storing the two parts of the string in two variables. The string is randomly selected from the text file and for example if the string is " Halloween - A holiday", I want the string to be separated on the basis of '-'. So the first string would be separated as "Haloween" and the second string would be stored as "-A holiday". The string could have any content but it should split based on the '-' and then the two strings should be stored in the two varaiblesarrow_forwardWhat is the output of the following C++ code? #include<iostream> using namespace std; class X { int m; public: X() : m(10) { } X(int mm): m(mm) { } int getm() { return m; } }; class Y : public X { int n; public: Y(int nn) : n(nn) {} int getn() { return n; } }; int main() { Y yobj( 100 ); cout << yobj.getm() << " " << yobj.getn() << endl; }arrow_forwardWrite a programme in C called pgmReduce which takes 3 arguments: an input file (either ASCII or binary) an integer factor n, and an output file and reduces the input file by that factor in each dimension. For example, if the invocation is: pgmReduce inputFile 5 outputFile and inputFile is a 13x17 image, then outputFile should be a 2x3 image in which only the pixels with row and column of 0 modulo 5 in the inputFile exist.arrow_forward
- Your task is to implement a variation of the classic word game Hangman, which involves players guessing the letters in a word chosen at random with a finite number of guesses. While there are alternate versions such as category Hangman and Wheel of Fortune, which involve players guessing idioms, places, names and so on, we will be sticking with the traditional version. Requirements:You will implement a function called main that allows users to play an interactive hangman game against the computer. The computer should pick a word, and players should then try to guess letters in the word until they win or run out of guesses.Here is the overarching behaviour we expect:1. The program should load a list of available words from the text file provided. Note that the file you have been given contains words in lowercase.2. The computer should then select a word at random from the list at random.3. The user is given a certain number of guesses at the beginning.4. The game is interactive; the…arrow_forwardWrite a complete C++ program in one file which takes a double value from the user, cubes it, and prints the result. Your program must use a function which takes a parameter for the value to be cubed and returns the result by reference. The function may not print anything or read anything directly from the user (i.e. no cin/cout in the function). Hint: n cubed is defined as n*n*n.arrow_forwardWrite a program using c++ that reads students’ names followed by their test scores. The program should output each student’s name followed by the test scores and the relevant grade. It should also find and print the highest test score and the name of the students having the highest test score. Student data should be stored in a struct variable of type studentType, which has four components: studentFName and studentLName of type string, testScore of type int (testScore is between 0 and 100), and grade of type char. Suppose that the class has 20 students. Use an array of 20 components of type studentType. Your program must contain at least the following functions: A function to read the students’ data into the array. A function to assign the relevant grade to each student. A function to find the highest test score. A function to print the names of the students having the highest test score. Your program must output each student’s name in this form: last name followed by a comma, followed…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
Call By Value & Call By Reference in C; Author: Neso Academy;https://www.youtube.com/watch?v=HEiPxjVR8CU;License: Standard YouTube License, CC-BY