Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with this please his exercise is designed to give you practice in in

ID: 3833759 • Letter: I

Question



I need help with this please

his exercise is designed to give you practice in input/out pat in oduce the data type ghara and also to introduce you using funotions and procedare modularize your code Firstly, write a tunction vaid lit ine [char ch int nun the character ch nun tires in a row on a given line. For examp write a function ly void rectang1 char ch int x int y vhich writes the character ch in a re of x rows ar pattern and y columns. For example 3.5) should output Function Frectangle" Rhould invoke function "line" to Hate complish its job111 Thirdly progran body to read one character at a of which is the Your Program, should Produce rectangular pattern for each letter in the anina the size of the lar pattern dependa an the letter and ce its Pakiti the rule being th letter of the alphabet the rectangle should be size by the f the inputted aninal name is CAT your progran should produce the output pattern in CAT is the 3 rd by 3 of the alphabet 2 by 1 since the 2 nd letter in CAT is the 1st letter of the alphabet since the rd 1 etter in CAT is 20 the 20 th letter of the alphabet continued on back)

Explanation / Answer

// Place the 'animals.dat' file in the same folder of this program

#include <iostream>
#include <string>
#include <fstream>
#include <iostream>

using namespace std;
void rectangle(char, int , int);/*prototype */
void line(char,int);

int main()
{
std::ifstream file;
file.open("animals.dat");

while (true) {
char ch;
file >> ch;
if( file.eof() ) break;
else{
int x=1;
int y=ch;
y = y-64; // Since ASCII value of capital 'A' is 65
while(ch != ' '){
rectangle(ch, x, y);
cout << " "; //New line for every single character in animal name
x=x+1;
}
cout << " "; // Severla lines for every animal name
}
}
//system("pause");
file.close();
return 0;
}

void rectangle(char ch, int x, int y){
for(int i=0; i<x; i++){
line(ch,y);
}
}
  
void line(char ch, int num){
for(int i=0; i<num; i++){
cout << ch ;
}