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

This is for a intro C++ class. I have my code that I submitted already and will

ID: 3665059 • Letter: T

Question

This is for a intro C++ class. I have my code that I submitted already and will give the feedback that was given on what needs to be corrected with it. Feel free to change it up as needed though. Here is the following assignment question:

Write a program that uses a for statement to print a table of ASCII values for the characters in the ASCII character set from 33 to 126. The program should print the decimal value,octal value,hexadecimal value and character value for each character. Use the stream manipulators dec, oct and hex to print the integer values.

****This is what was given to me for feedback that I need to correct with the program that I had submitted:

* Global variables are not allowed.

* Hex numbers should be preceded by the string “0x”, and octal numbers should be preceded by the string “0”.

* Put long output in a file and inform the user of its name before exiting.

Here is the following code that I had:

#include <iostream>
#include <iomanip>
using namespace std;

struct ascii
{
   char ch;
   int val;
}

asc[300];                                                       //array for storage of ascii values & chars

int main() {

   int i;                                                       //variable for incrementation

   for (i = 33; i <= 126; i++)                                   //for loop of incrementation
   {
       asc[i].val = i;
       asc[i].ch = (char)i;
   }

   cout << setw(5) << "Dec" << setw(5) << "oct" << setw(5)       //output headers
       << "hex" << setw(5) << "char" << endl;

   for (i = 33; i <= 126; i++)
   {
       cout << dec << setw(5) << asc[i].val << oct <<           //output dec, oct, hex and char values for
           setw(5) << asc[i].val << hex << setw(5) <<           //each ASCII value
           asc[i].val << setw(5) << asc[i].ch;
       cout << endl;                      

   }

   system("pause");
   return 0;
}

As stated you can change the program up, that is what I submitted and that was the feedback I received that I need to correct to improve the program.

Thank you

Explanation / Answer

// Include files #include // used for cin, cout #include #include #include using namespace std; // Global Type Declarations // Function Prototypes void instruct (void); void pause (); //Global Variables - should not be used without good reason. int main () { // Declaration section int runs, row; ofstream odf; // Executable section instruct (); odf.open ( "outputfile.txt", ios::out ); if ( odf.fail()){ cerr
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