Starting Out with C++ from Control Structures to Objects (9th Edition)
9th Edition
ISBN: 9780134498379
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 10.4, Problem 10.7CP
Program Plan Intro
“strlen” function:
The “strlen” function accepts a string as an argument and returns the full length of the string, but it will not include the null character (‘\0’).
Example:
Consider the example of the “strlen” function is as follows:
char a [10] = "Hai";
int value = strlen (a);
Here, the variable “value” will store 3, because the length of the “a” string is 3.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Complete the function empty which returns true if s1 has a length of 0. You may not use any library
functions from .
cstrings.cpp
#include
using namespace std;
bool empty(const char* s)
{
1
4
5
7
8
}
What will the following program segment display?
char dog[] = "Fido";cout << strlen(dog) << end1;
#include <stdio.h>#include <string.h> int main(){ char str[10][30] = { "Utkarsh","Ayush","Gautam", "Mustafa", "Aman", "Sonu","Rahul", "Sooraj","Mohit","Sunil"}; char temp[30]; for(int i = 0; i < 10; i++){ for(int j = 0; j < 9 - i; j++){ if(strcmp(str[j], str[j+1]) < 0){ strcpy(temp, str[j]); strcpy(str[j], str[j+1]); strcpy(str[j+1], temp); } } } printf("The names in descending order are :: \n\n"); for(int i = 0; i< 10; i++) printf("%s ", str[i]);
return 0;}
Extend your program in to do a binary search on the list of names. Search the 8th name from your original list and return the position of the name from the sorted name list
Chapter 10 Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
Ch. 10.2 - Write a short description of each of the following...Ch. 10.2 - Prob. 10.2CPCh. 10.2 - Write an if statement that will display the word...Ch. 10.2 - What is the output of the following statement?...Ch. 10.2 - Write a loop that asks the user Do you want to...Ch. 10.4 - Write a short description of each of the following...Ch. 10.4 - Prob. 10.7CPCh. 10.4 - Prob. 10.8CPCh. 10.4 - Prob. 10.9CPCh. 10.4 - When complete, the following program skeleton will...
Ch. 10.5 - Write a short description of each of the following...Ch. 10.5 - Write a statement that will convert the string 10...Ch. 10.5 - Prob. 10.13CPCh. 10.5 - Write a statement that will convert the string...Ch. 10.5 - Write a statement that will convert the integer...Ch. 10.6 - Prob. 10.16CPCh. 10 - Prob. 1RQECh. 10 - Prob. 2RQECh. 10 - Prob. 3RQECh. 10 - Prob. 4RQECh. 10 - Prob. 5RQECh. 10 - Prob. 6RQECh. 10 - Prob. 7RQECh. 10 - Prob. 8RQECh. 10 - Prob. 9RQECh. 10 - Prob. 10RQECh. 10 - The __________ function returns true if the...Ch. 10 - Prob. 12RQECh. 10 - Prob. 13RQECh. 10 - The __________ function returns the lowercase...Ch. 10 - The _________ file must be included in a program...Ch. 10 - Prob. 16RQECh. 10 - Prob. 17RQECh. 10 - Prob. 18RQECh. 10 - Prob. 19RQECh. 10 - Prob. 20RQECh. 10 - Prob. 21RQECh. 10 - Prob. 22RQECh. 10 - Prob. 23RQECh. 10 - Prob. 24RQECh. 10 - The ________ function returns the value of a...Ch. 10 - Prob. 26RQECh. 10 - The following if statement determines whether...Ch. 10 - Assume input is a char array holding a C-string....Ch. 10 - Look at the following array definition: char...Ch. 10 - Prob. 30RQECh. 10 - Write a function that accepts a pointer to a...Ch. 10 - Prob. 32RQECh. 10 - Prob. 33RQECh. 10 - T F If touppers argument is already uppercase, it...Ch. 10 - T F If tolowers argument is already lowercase, it...Ch. 10 - T F The strlen function returns the size of the...Ch. 10 - Prob. 37RQECh. 10 - T F C-string-handling functions accept as...Ch. 10 - T F The strcat function checks to make sure the...Ch. 10 - Prob. 40RQECh. 10 - T F The strcpy function performs no bounds...Ch. 10 - T F There is no difference between 847 and 847.Ch. 10 - Prob. 43RQECh. 10 - char numeric[5]; int x = 123; numeri c = atoi(x);Ch. 10 - char string1[] = "Billy"; char string2[] = " Bob...Ch. 10 - Prob. 46RQECh. 10 - Prob. 1PCCh. 10 - Prob. 2PCCh. 10 - Prob. 3PCCh. 10 - Average Number of Letters Modify the program you...Ch. 10 - Prob. 5PCCh. 10 - Prob. 6PCCh. 10 - Name Arranger Write a program that asks for the...Ch. 10 - Prob. 8PCCh. 10 - Prob. 9PCCh. 10 - Prob. 10PCCh. 10 - Prob. 11PCCh. 10 - Password Verifier Imagine you are developing a...Ch. 10 - Prob. 13PCCh. 10 - Word Separator Write a program that accepts as...Ch. 10 - Character Analysis If you have downloaded this...Ch. 10 - Prob. 16PCCh. 10 - Prob. 17PCCh. 10 - Prob. 18PCCh. 10 - Check Writer Write a program that displays a...
Knowledge Booster
Similar questions
- cout << x <<"\t“ << 11 – x << endl;} 3- { int i; int arr[5] = {1}; for (i = 0; i< 5; i++) cout<arrow_forward#include <iostream> #include<string.h> //user-defined functions question! using namespace std; struct Books { char title[50]; char author[50]; char subject[100]; int book_id; }; int main() { double array1[5]= {13.768,4.0,88.7689,9.12,}; struct Books Book1; strcpy( Book1.title, "C++ Programming"); strcpy( Book1.author, "D.S Malik"); strcpy( Book1.subject, "C++ basics"); Book1.book_id = 6495407; ////Block#1////// int x=4; for (x; x>=0; x--){ cout<<array1[x]<<endl; //////////////////////////////// } cout<<"///////////////////////"<<endl; ////end of Block#1////// ////Block#2////// int sum=0, i=0; for (i; i<5; i++){ cout<<static_cast<int>(array1[i])<<" "; sum= sum+array1[i]; cout<<sum<<endl; } cout<< "final value of sum="<<" "<<sum<<endl; cout<< "the average value ="<<" " <<sum/5 <<endl; cout<<"//////////////////////"<<endl; //arrow_forward#include <iostream> #include<string.h> //user-defined functions question! using namespace std; struct Books { char title[50]; char author[50]; char subject[100]; int book_id; }; int main() { double array1[5]= {13.768,4.0,88.7689,9.12,}; struct Books Book1; strcpy( Book1.title, "C++ Programming"); strcpy( Book1.author, "D.S Malik"); strcpy( Book1.subject, "C++ basics"); Book1.book_id = 6495407; ////Block#1////// int x=4; for (x; x>=0; x--){ cout<<array1[x]<<endl; //////////////////////////////// } cout<<"///////////////////////"<<endl; ////end of Block#1////// ////Block#2////// int sum=0, i=0; for (i; i<5; i++){ cout<<static_cast<int>(array1[i])<<" "; sum= sum+array1[i]; cout<<sum<<endl; } cout<< "final value of sum="<<" "<<sum<<endl; cout<< "the average value ="<<" " <<sum/5 <<endl; cout<<"//////////////////////"<<endl; //arrow_forwardWrite EBNF formarrow_forward/*Line 1:*/ doublevalues[6] = {10, 20, 30, 40, 50, 60}; /*Line 2:*/ double* yalptr= values; /*Line 3:*/ cout << 3*values[1] + yalptr[3] + *(valptr + 2); A. What is 3*values[1] equal to in Line 3? (Explain) B. What is yalptr[3] equal to in Line 3? (Explain)arrow_forward#include <stdio.h>#include <string.h>#define SIZE 6struct Student{char name[50];int id;float mark;};int Search1(char input[], struct Student data[]);int Search2(int input, struct Student data[]);int main() {char search_name[30];int search_id;int result1, result2;struct Student list[SIZE] = {{"Amylia", 544199, 75.4},{"Cheong", 143566, 92.3},{"Harry", 109774, 65.5},{"Krishnan", 334514, 86.7},{"Melissa", 257890, 55.4},{"Timothy",144656, 77.8}};printf("Enter Student Name: ");gets(search_name);result1 = Search1(search_name, list);//Answer for part (a)(ii) – Display the matching index of result1printf("Enter Student ID: ");scanf("%d",&search_id);result2 = Search2(search_id,list);//Answer for part (a)(iii)- Display the matching index of result2return 0;}//Answer for part (a)(i) – function definition for Search1//Answer for part (a)(iii) – function definition for Search2arrow_forwardin c language typedef _people { int age; char name[ 32 ] ; } People_T ; People_T data [ 3 ]; Using string lib function, Assign 30 and Cathy to the first cell, Assign 40 and John to the second cell and Assign 50 and Tom to the third cellarrow_forwardC++ Coding Write a program that asks a teacher to enter the student's and the grades received on her quarterly exams. The datatype for the student's name could be a string and the four grades should be entered in an array of data types int. Test scores are on the base of 100. The main() functions describe the average function with the following title line: double avg( int grades[] , int cap ): The program prints the student's name, her four grades, and her average grades. The main() function also uses the following print function: void print( int grades[], int cap);arrow_forward#include <iostream> #include <ctime> #include <cmath> const int MAX = 1000; const char CLASS[] = {'A','B','C'}; struct Points{ int x,y; char c; double dist(Points q){ return sqrt(pow(x-q.x,2)+pow(y-q.y,2)); } }; int main(){ return 0; } int main(){ srand(time(0)); }arrow_forward#include <iostream>using namespace std;struct item{ int id; float price;} s[50];int size = 0;void addData() { cout << "Enter an item data " << endl; cout << "Enter id: "; cin >> s[size].id; cout << "Enter price: "; cin >> s[size].price; cout << "successfully added" << endl << endl; size++; for (int i = 0; i < size; i++) { for (int j = i + 1; j < size; j++) { if (s[i].price > s[j].price) { struct item t = s[i]; s[i] = s[j]; s[j] = t; } } }}void retrivePrice() { int id; cout << "enter the element id:"; cin >> id; cout << endl; int i; for (i = 0; i < size; ++i) { if (id == s[i].id) { cout << "price for this item: " << s[i].price << endl << endl; break; } } if (i == size) cout…arrow_forward#include <iostream>using namespace std;struct item{ int id; float price;} s[50];int size=0; void addData(){ cout << "Enter an item data " << endl; cout << "Enter id: "; cin >> s[size].id; cout << "Enter price: "; cin >> s[size].price; cout<<"successfully added"<<endl<<endl; size++; for(int i=0;i<size;i++) { for(int j=i+1;j<size;j++) { if(s[i].price>s[j].price) { struct item t=s[i]; s[i]=s[j]; s[j]=t; } } }}void retrivePrice(){ int id; cout<<"enter the element id:"; cin>>id; cout<<endl; int i; for( i = 0; i < size; ++i) { if(id == s[i].id){ cout << "price for this item: " << s[i].price << endl<<endl;…arrow_forwardNumber guessing Game Write a C program that implements the “guess my number” game. The computer chooses a random number using the following random generator function srand(time(NULL)); int r = rand() % 100 + 1; that creates a random number between 1 and 100 and puts it in the variable r. (Note that you have to include <time.h>) Then it asks the user to make a guess. Each time the user makes a guess, the program tells the user if the entered number is larger or smaller than its number. The user then keeps guessing till he/she finds the number. If the user doesn’t find the number after 10 guesses, a proper game over message will be shown and the actual guess is revealed. If the user makes a correct guess in its allowed 10 guesses, then a proper message will be shown and the number of guesses the user made to get the correct answer is also printed. After each correct guess or game over, the user decides to play again or quit and based on the user choice, the computer will make…arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_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