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

Here is a question that I have for a programming class. I don\'t know where to s

ID: 3766273 • Letter: H

Question

Here is a question that I have for a programming class. I don't know where to start with the code.

Your workplace is starting to become concerned with the cost of toner used for printing. Of course, some pages are more expensive to print than others. Your job is to write a program that helps to gure out how many units of toner it will take to print various strings of characters. For any given font, each character requires a certain amount of toner to print. For example, in the Goober Extended 12 point font, a space requires no toner, but a capital Q requires 31 units of toner. The following table gives the printing cost of each of the 95 printable ASCII characters in the Goober Extended font.
h 21 i 15 j 20 k 21 l 16 m 22 & 24 ' 3 ( 12 ) 12 * 17 + 13 t 17 u 17 v 13 w 19 x 13 y 24 , 7 - 7 . 4 / 10 0 22 1 19 2 22 3 23 4 21 5 27 6 26 7 16 8 23 9 26 : 8 ; 11 < 10 = 14 > 10 ? 15 @ 32 A 24 B 29 C 20 V 19 W 26 X 18 Y 14 Z 22 [ 18 b 25 c 17 d 25 e 23 f 18 g 30 D 26 E 26 F 20 G 25 H 25 I 18 n 18 o 20 p 25 q 25 r 13 s 21 J 18 K 21 L 16 M 28 N 25 O 26 z 19 { 18 | 12 } 18 ~ 9 % 22 10 ] 18 ^ 7 _ 8 ` 3 a 23 P 23 Q 31 R 28 S 25 T 16 U 23 ! 9 " 6 # 24 $ 29
Your assistant has already created a similar table for every 12 point font used within your company. If text is printed with a di erent point size, then the amount of toner required changes proportionally. For example a 14 point exclaimation point would require 14 12 9 units of toner.
Input
The main input le consists of a sequence of zero or more records. Each record consists of a line containing the name and point size of the font used, followed by a line of text. Each line of text is at most 1000 characters long. The name of the input le will be given as the rst command line argument. If the le name is not given on the command line, or if the le
1
cannot be opened, then your program should print an appropriate message and exit with a non-zero return code. There will be no more than 1000 records in the input le. You also be given a set of les containing the tables of toner usage for every possible 12 point font, as previously described. Each le name is in the format .tnr where is the name of a font, with all characters lower-case and with all space characters converted to underscore characters. For example the table for the 12 point Goober Extended" font will be stored in the goober_extended.tnr" le. The toner usage les consist of a series of pairs. Each pair consists of a character and an integer number of toner units required to print that character. The characters in each toner usage le are not in any particular order, and the order is di erent from one le to the next. Toner usage for any character not listed in the toner usage le must be assumed to be zero.
Output
For each input record (font name, size, and line of text), output a line giving the record number, the total amount of toner required for printing the given text in the given font at the given size, and the string to be printed. The output lines must be sorted in ascending order by the amount of toner required. The name of the output le will be given as the second command line argument. If the le name is not given on the command line, or if the le cannot be opened, then your program should print an appropriate message and exit with a non-zero return code.
Required Functions
Your program must implement at least the following ve functions (with appropriate arguments):
// Get the point size from an input string int extractPointSize()
// Sort the "records" by cost void sortByCost()
// Use the font name to read the data file void readFontData()
// Use the font data and string to be printed int getTonerUsed()
// Print a message about how to use the program void printUsage()
2
Sample Input
Misc-Crackling-medium-r-normal 12 This is a short line. misc-Futura Poster-light-r-normal 24 THIS IS A LONGER, MORE EXPENSIVE LINE. misc-cmr10-medium-r-normal 10 This is cheap.
Sample Output
Record: 3 Font: misc-cmr10-medium-r-normal Size: 10 Toner required: 2179 String: This is cheap.
Record: 1 Font: Misc-Crackling-medium-r-normal Size: 12 Toner required: 6868 String: This is a short line.
Record: 2 Font: misc-Futura Poster-light-r-normal Size: 24 Toner required: 16880 String: THIS IS A LONGER, MORE EXPENSIVE LINE.

Explanation / Answer

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <cctype>
#include <cstdlib>
#include <algorithm>
using namespace std;

const int MAX_FILE = 1000;


int main(int argc, char *argv[])
{
ifstream fin;
ofstream fout;
char openfile[MAX_FILE];
char fontLine[500] = { 0 };


if (argc != 2)
{
  cout << "Incorrect input, program4 data.in" << endl;
}

strcpy(openfile, argv[argc - 1]);

fin.open(openfile);
if (!fin)
{
  cout << "Unable to open the file: data.in" << endl;
  fin.close();
  return -1;
}

}

int extractPointSize()
{
ifstream fin;
{
  unsigned long Size = 0;
  string Temp;

  for (size_t i = 0; i < str.length(); ++i)
  {
   if (isdigit(str[i]))
   {
    if (isspace(str[i - 1]))
    {
     Temp = str.substr(i, string::npos);
     Size = strtoul(Temp.c_str(), NULL, 0);

     return Size;
    }
   }
  }
    {
     return 0; //NOT FOUND

    }
}
};

void sortByCost();

void readFontData();

int getTonerUsed();

void printUsage();