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

C++ program debug my assigment need me to use a input file while read the file p

ID: 3855734 • Letter: C

Question

C++ program debug

my assigment need me to use a input file while read the file print out if the text in side are letter (upper case or lower case) or number (odd or even)

I got my own code down there please help

#include <iostream>

#include <fstream>

void ShowProgramHeader();

void IsLetter(char Gets);

void IsDigit(int Gets);

using namespace std;

int main()

{

int i = 1;

char Gets[i];

  

ifstream readFile;

readFile.open("data.txt");

if(!readFile)

{

cout<<"Error the file can't be open!!"<<endl;

exit(1);

}

  

while(readFile)

{

  

readFile.get(Gets[i]);

if((Gets[i] >= 'A'&& Gets[i] <= 'Z')||(Gets[i] >= 'a'&& Gets[i] <= 'z'))

{

IsLetter(Gets[i]);

}

else if(Gets[i] >= '0'&& Gets[i] <= '9')

{

IsDigit(Gets[i]);

}

i++;

  

}

readFile.close();

return 0;

}

void Isletter(char Gets)

{

cout<<" "<<Gets<<" is a letter!"<<endl;

if(Gets >= 'A'&& Gets <= 'Z')

cout<<Gets<<" is upper case! ";

else if(Gets >= 'a'&& Gets <= 'z')

cout<<Gets<<" is lower case! ";

}

void IsDigit(int Gets)

{

cout<<" "<<Gets<<" is a Number!"<<endl;

if(Gets % 2 == 0)

cout<<Gets<<" is a Even Number! ";

else

cout<<Gets<<" is a Odd Number! ";

}

and this is the error is show:

"IsLetter(char)", referenced from:

clang: error: linker command failed with exit code 1 (use -v to see invocation)

Explanation / Answer

#include <iostream>
#include <fstream>
using namespace std;
int main () {
fstream file;//Stream class to both read and write from/to files
char data;
int i;
//create a text file information.txt
file.open ("information.txt",ios::in|ios::out); // ios::in open file for input operations
// ios::out open file for output operations
if(!file.is_open())
//is_open() is a member function returns boolean value true or false to check whether file is successfully opened or not
{
cout<<"error while opening the file";
}
else{
cout<<"File opened successfully ";
//read the information in the file character by character and store that character in variable name 'data'
while(file>>data)
{
//check whether each character is letter or not
if((data >= 'A'&& data <= 'Z')||(data >= 'a'&& data <= 'z'))
{
//if each character is upper case or lower case letter
if(data >= 'A'&& data <= 'Z')
cout<<data<<" is upper case! ";
else if(data >= 'a'&& data <= 'z')
cout<<data<<" is lower case! ";
}
//if character is not a letter then check whether its a number
else if(data >= '0'&& data <= '9')
{
//if its a number check whether its a even number or odd number
if(data % 2 == 0)
cout<<data<<" is a Even Number! ";
else
cout<<data<<" is a Odd Number! ";
}
i++;
}
//close the opened file
file.close();
}
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote