//Problem #1: [] // ------------------------------------------------------------
ID: 3551174 • Letter: #
Question
//Problem #1: []
// ------------------------------------------------------------------
// Function: Complete the following program
// a) Read (using >>) a character Letter;
// b) Read (using getline) a C-string Line (capacity up
// to 80 characters)
// c) Count the #times Letter appears in Line.
// d) Print the length of Line, the letter, and the number
// times it occurs.
//
// Example: Input: oGood Job ==> 8 o3
// AFatCat ==> 6 A0
// 8123848 8 2 => 10 83
// ------------------------------------------------------------------
#include <iostream>
using namespace std;
int main()
{
char Line[81]; char Letter;
int count=0;
// --------------------------------------------------------------------
// WARNING: DO NOT ISSUE PROMPTS or LABEL OUTPUT.
// --------------------------------------------------------------------
cout << strlen(Line) << " " << Letter << count;
cout << endl; // *** DO NOT REMOVE ***
return 0;
}
//Problem #2: []
// ------------------------------------------------------------------
// Function: Complete the following program
// a) Read a count.
// b) Read (>>) C-string Word (capacity up to 10 characters)
// c) Create C-string Answer (capacity up to 20 characters).
// d) Place up to count copies of Word into C-string Answer,
// but do not overflow Answer.
// e) Print th length of Answer, followed by its value.
//
// Example: Input: 4 12345 ==> 20 12345123451234512345
// 2 FatCat ==> 12 FatCatFatCat
// 8 abc134. ==> 14 abc134.abc134.
// ------------------------------------------------------------------
#include <iostream>
using namespace std;
int main()
{
char Cstr[11], Answer[21];
int count, times=1;
// --------------------------------------------------------------------
// WARNING: DO NOT ISSUE PROMPTS or LABEL OUTPUT.
// --------------------------------------------------------------------
cout << endl; // *** DO NOT REMOVE ***
return 0;
}
//Problem #3: []
// ------------------------------------------------------------------
// Function: Complete the following program
// a) Read (>>) string str (can hold 20 characters)
// b) Print EVEN if length of str is even; ODD otherwise.
//
// Example: Input: FAT ==> ODD
// Input: CATWOMAN ==> EVEN
//
// ------------------------------------------------------------------
#include <iostream>
using namespace std;
int main()
{
// --------------------------------------------------------------------
// WARNING: DO NOT ISSUE PROMPTS or LABEL OUTPUT.
// --------------------------------------------------------------------
cout << endl; // *** DO NOT REMOVE ***
return 0;
}
Explanation / Answer
Q1).
#include <iostream.h> // for hidder file
int main()
{
char Line[81]; char Letter;
int count = 0;
cin>>Letter;
cin.getline(Line,81);
for(int i=0;i<strlen(Line);i++)
{
if(Line[i]==Letter)
count++;
}
cout <<'' strlen(Line) << " " << Letter << count;
cout << endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.