EBK DATA STRUCTURES AND ALGORITHMS IN C
4th Edition
ISBN: 9781285415017
Author: DROZDEK
Publisher: YUZU
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 1, Problem 2E
Program Plan Intro
Pointers:
- A variable whose value is another variable’s address is termed as pointer.
- A pointer is to be declared before being used.
- The declaration syntax for a variable that is a pointer is shown below:
type *lvarname;
- Here, “type” is a pointer's base type and “lvarname” is pointer variable’s name.
- The asterisk sign is been used for pointer declaration.
- The asterisk sign is being used for designation of a variable as a pointer.
Explanation of Solution
b.
Identification of errors:
Before copying “s2” to “s1”, memory has to be allocated for accommodating contents of “s1”, as shown below:
...
Explanation of Solution
c.
Identification of errors:
While memory allocation for contents of “s2” is performed, one more character has to be allocated for the end-of-string character. In the given syntax, one more character allocation is needed...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
In C++:
Examine the code segment. What will be printed?
If there are any errors indicate the nature of each error.
int a[7] = {31, 12, 32, 14, 25, 16, 27};
int *ptr;
ptr = & a[2];
for ( i=1; i<=5; i=i+2)
cout << *(ptr +i);
cout << a[0] << *ptr << *ptr - 2 << *(ptr -1)) << endl;
A palindrome is a string that reads the same forwards or backwards; for example dad, mom, deed are palindromes (i.e., reversing a palindrome produces the same string).
Use C++ Programing language
Write a recursive, boolean-valued function, isPalindrome that takes a string as a parameter and returns whether the string is a palindrome.
A string, s, is a palindrome if:
s is the empty string or s consists of a single letter (which reads the same back or forward), or
the first and last characters of s are the same, and the rest of the string (i.e., the second through next-to-last characters) form a palindrome.
Write a test program that reads a string from the standard input device and outputs whether the input string is a palindrome or not.
Convert this into C programming. Thanks!...
#include <iostream>
#include<iomanip>
using namespace std;
int main()
{
int length = 20;
for (int i = 0; i <= 120; i++) {
cout << "=";
}
cout << endl;
cout.width(10);
cout << "";
for (int i = 1; i <= 10; i++) {
cout.width(10);
cout << i;
}
cout << endl;
for (int i = 0; i <= 120; i++) {
cout << "-";
}
cout << endl;
for (int i = 1; i <= length; i++) {
cout.width(10);
cout << i << "|";
for (int j = 1; j <= 10; j++) {
cout.width(10);
cout << i * j;
}
cout << endl;
}
return 0;
}
Chapter 1 Solutions
EBK DATA STRUCTURES AND ALGORITHMS IN C
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
short answers :
c)Give an example of a common floating point arithmetic error due to the particular way in which floating point numbers are stored?
d)Give an example of how when using C-strings and the functionstrcpy, things can go wrong.
arrow_forward
• R7.17Consider the following code that repeats a C++ string three times.
string a = "Hello";
string b = a + a + a;
Suppose s is a C string, and t is declared as
char t[100];
Write the equivalent code for C strings that stores the threefold repetition of s (or as much of it as will fit) into t.
arrow_forward
In C, Given a char variable c that has already been declared, write some code that repeatedly reads a value from standard input into c until at last a 'Y' or 'y' or 'N' or 'n' has been entered.
arrow_forward
Please write the following program in C. Write the complete program with correct syntax.
Take a string input from the user and find out whether it is a palindrome using pointers.
Sample Input:AAABBAAAAABBABAaabcbaaSample Output:PalindromeNot PalindromePalindrome
arrow_forward
Solve the problem in C++
(Anagrams)
Write a function that checks whether two words are anagrams. Two words are anagrams if they contain the same letters in any order. For example, “silent” and “listen” are anagrams.
The header of the function is as follows:
bool isAnagram(const string& s1, const string& s2)
Write a test program that prompts the user to enter two strings and checks whether they are anagrams.
Sample Run 1
Enter a string s1: silent
Enter a string s2: listen
silent and listen are anagrams
Sample Run 2
Enter a string s1: split
Enter a string s2: lisp
split and lisp are not anagrams
arrow_forward
5: CheckLetter.cpp) Write a program that adds a checkletter to an eight-digit number. The check letter should becomputed as follows: Break the number up into 4 two-digitnumbers. Add the four numbers together. Find theremainder after division by 26. The check letter is the letterin the alphabet that corresponds to the number justcomputed. (A=0, B=1, C=2, etc.) Print the original numberfollowed by the check letter. Use at least one ffunction thatreturns a value when you write this program.
arrow_forward
Fibonacci’s sequence starts with values 1 and 1. The next value in the sequence is formed by summing the previous two values. Thus the third value is 1+1=2, the fourth is 1+2=3, the fifth is 2+3=5, etc. Thus, the sequence is 1, 1, 2, 3, 5, 8, 13, 21, …. Write a code fragment using c++ that obtains a positive integer n from the user and displays the sum of the first n numbers in the Fibonacci sequence. If n is not positive, use cout to print out an error message. Put this code fragment in your main() of your project.
arrow_forward
In c++ , perform deletion at the start, middle and end as well and perform the shrinking operation as well.
( Drop code in words , explain the code and drop the screenshot of output as well )
arrow_forward
a) Give an example of a string that is neither in the language of R nor in S.
b) Give an example of a string that is in the language of S but not R.
c) Give an example of a string that is in the language of R but not S.
d) Give an example of a string that is in the language of R and S.
e) Design a regular expression that accepts the language of all binary strings with no occurrences of 010.
arrow_forward
The question should be done in C++, please give explanation and running result.
1. Let’s write a function that compares 2 strings and returns true if they were identical, false otherwise. The signature of this function should be:
bool word_diff(std::string word1, std::string word2);
For example:
std::string str1 = "Hello World";std::string str2 = "hEllO World";std::string str3 = "World";std::string str4 = "Hello World";bool result = word_diff(str1, str2); // Falsebool result = word_diff(str1, str3); // Falsebool result = word_diff(str1, str4); // True
2. Now let’s follow a classical approach to compare the content of 2 files. We should open each file, read their content word by word and compare them until a first mismatch occurs.Let’s implement a function called classical_file_diff that takes 2 arguments each of which is a file name and returns a boolean indicating whether the 2 files are identical or not. The signature of this function should be:
bool…
arrow_forward
Please use easy logic with proper indentations and comments for understanding!. Coding should be in C++.
2. Write a recursive function that reads words from the standard input stream and displays them in reverse order on the standard output stream. For example, if the input was: here comes the sun, the output would be: sun the comes here. Hint: Read individual words until the end of a sentence is reached. You can determine the end of the sentence any way you like. Some suggestions include (a) checking the last character of a word for a sentence terminator (. ? ! ) (b) Using a keyword such as 'quit' to indicate the end of input. (c) Using the eof method of the cin object. (ctrl Z for windows or ctrl D for others can be used to force an end of file from the keyboard.)
arrow_forward
2. Write a program in C to find the length of string S1 and compare the string length with S3
arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning