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

Write a Program in C++ In which 1) Read the user file and Generate Corresponding

ID: 3784073 • Letter: W

Question

Write a Program in C++ In which

1) Read the user file and Generate Correspondingly ASCII value of each character in file.

2) Divide every character ASCII value by 10. Calculate Quotient, Reminder and Quotient values stored in Q block, Reminder values stored in R block correspondingly.

3) Calculate 8-bit binary value for each value that is in R block and Q block correspondingly.

Please i need this program in C++ language. if anybody want to do in Java then its ok! do it.

But according to requirements it should work

Explanation / Answer

#include<iostream>
#include<conio.h>

using namespace std;

int main()
{
ifstream inp(file);
char c;
long Q,R;
long rem1,rem2,i=1,j=1,sum1=0,sum2=0;

if(inp.is_open()) {
while(inp.good()) {
inp.get(c);
   cout << "Character is: " << c;
   cout << "ASCII Value of " << c << " is " << int(c); //coversion to ascii value

       Q = c/10;
       R = c%10;

       // Converting Q into binary
      do
       {
   rem1=Q%2;
       sum1=sum1 + (i*rem1);
   Q=Q/2;
   i=i*10;
       }while(Q>0);
  
       // Converting R into binary
       do
       {
   rem2=R%2;
       sum2=sum2 + (j*rem2);
   R=R/2;
   j=j*10;
       }while(R>0);

   cout<<"The binary of the given number is:"<<sum1<<sum2<<endl;
   String out1 = String.format("%8s", sum1).replace(' ', '0'); //coverting Q to 8-bit binary by padding zeros to left
   String out2 = String.format("%8s", sum2).replace(' ', '0');   //coverting R to 8-bit binary by padding zeros to left

cout<<"8-bit binary value of Q and R is:"<<out1<<out2<<endl;
}
}

if(!inp.eof() && inp.fail())
cout << "error occured reading the file " << file << endl;

inp.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