#include #include #include #include using namespace std; int countA(char * str);
ID: 3654066 • Letter: #
Question
#include #include #include #include using namespace std; int countA(char * str); int main() { char city1[20] = "San Francisco"; char city2[20] = "Sonoma"; char city3[15] = "Lake Tahoe"; string sport1 = "Snowboard"; string sport2 = "Basketball"; string sport3 = "Baseball2Day"; string s4 = "catastrophe"; cout << "Test" << s4.find("phe",0) << endl; //1. Write a c++ statment that prints any capital letter in city3 //2. Write a c++ statement that print's "yes" if there is a //digit in the variable sport3" //3. Write a c++ statement that compares //city3 and city2 and prints "equal" // if they are equal and "not equal" if they are not equal. //4. Write a c++ statement that Appends the word "Tournament" //to the variable sport2 //5. write a function that accepts a pointer to a C-string as //its argument. //The function should count the //number of times the character 'w' occurs in the argument and return //that number return 0; }Explanation / Answer
Please rate...
Completed program:
=======================================================
#include<iostream>
#include<string>
#include<string.h>
using namespace std;
int countA(char * str);
int main()
{
char city1[20] = "San Francisco";
char city2[20] = "Sonoma";
char city3[15] = "Lake Tahoe";
string sport1 = "Snowboard";
string sport2 = "Basketball";
string sport3 = "Baseball2Day";
string s4 = "catastrophe";
cout << "Test" << s4.find("phe",0) << endl;
//1. Write a c++ statment that prints any capital letter in city3
cout<<city3[0]<<" ";
//2. Write a c++ statement that print's "yes" if there is a
//digit in the variable sport3"
if(sport3.find('0')||sport3.find('1')||sport3.find('2')||
sport3.find('3')||sport3.find('4')||sport3.find('5')||
sport3.find('6')||sport3.find('6')||sport3.find('8')||
sport3.find('9'))cout<<"yes"<<" ";
//3. Write a c++ statement that compares
//city3 and city2 and prints "equal"
// if they are equal and "not equal" if they are not equal.
if(strcmp(city3,city2)==0)cout<<"equal"<<" ";
else cout<<"not equal"<<" ";
//4. Write a c++ statement that Appends the word "Tournament"
//to the variable sport2
sport2+="Tournament";
return 0;
}
//5. write a function that accepts a pointer to a C-string as
//its argument.
//The function should count the
//number of times the character 'w' occurs in the argument and return
//that number
int countA(char *a)
{
int c=0;
do
{
if(*a=='w')c++;
}while(*a++!='');
return c;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.