Question

use c# visual studio Design a program that reads in an ASCII text file (provided) and...

use c# visual studio

Design a program that reads in an ASCII text file (provided) and creates an output file that contains each unique character and the number of time the character appears in the file. Do not sort the output. Each unique character in the file must be represented by a character frequency class instance. For this exercise, the character frequency objects must be stored in a Linked List. Read the input file character-by-character. Reading the entire file into memory is prohibited.



For example, given the sample input file:
Hello.
The output file would look like this:

H(72) = 1 e(101) = 1 l(108) = 2 o(111) = 1 .(46) = 1

Where the format of the file is the character followed by the character’s ASCII value followed by the number of times the character occurred in the file.

The program should be able to be executed from the command line using the following syntax: programname.exe <inFile> <outFile>

For example, counter.exe myInput.txt Count.txt

Where counter.exe is the program name, myInput.txt is the input ASCII file, and the Count.txt is the output file.

The character frequency class must implement the properties and methods given in the UML diagram below. Note that the actual names of the methods can vary slightly based upon the language used. For example, the method getCharacter() would be appropriate for Java and C++; however, the property get method called, “Character” would be appropriate for C#/VB.

CharacterFrequency

-ch : char

-frequency : int

+getCharacter() : char

+setCharacter(character : char)

+getFrequency() : int

+setFrequency(frequency : int)

+increment()

+Equals() : bool

+ToString() : string

0 0
Add a comment Improve this question Transcribed image text
Answer #1

////source code in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace AssignmentV
{
public class Program
{
static void Main(string[] args)
{
const byte INPUT_FILENAME = 0;
const byte OUTPUT_FILENAME = 1;
CharacterFrequency[] characterArray = new CharacterFrequency[256];
for (int i = 0; i < 256; i++)
{
characterArray[i] = new CharacterFrequency((char)i);
characterArray[i].setCharacter((char)i);
}
if (args.Length != 2)
{
Console.WriteLine("Usage: CommandLine [input filename] [output file name]");
Environment.Exit(0);
}
Console.WriteLine("The input filename is: {0}", args[INPUT_FILENAME]);
Console.WriteLine("The output filename is: {0}", args[OUTPUT_FILENAME]);
using (StreamReader SR = new StreamReader(args[INPUT_FILENAME]))
{
int read;
FileInfo file = new FileInfo(args[INPUT_FILENAME]);
long fileLength = file.Length;
int f = Convert.ToInt32(fileLength);
string path = File.ReadAllText(args[INPUT_FILENAME]);
  
char[] block = new char[1024];
for (int k = 0; k < (f/1024); k++)
{
  
read = SR.ReadBlock(block, 0, block.Length);

for (int i = 0; i < read; i++)
{
characterArray[(block[i])].increment();
}
}
string text;
int Cfrequency=0;
for (int i = 0; i < characterArray.Length; i++)
{
text = ((("") + (char)i + ("(") + i.ToString()) + (")") + " " + characterArray[i].getFrequency(Cfrequency).ToString() + Environment.NewLine);
File.AppendAllText(args[OUTPUT_FILENAME], text, Encoding.UTF8);
}
}
}
}
}
/// second name Space
namespace AssignmentV
{
public class CharacterFrequency
{
private char CFCharacter;
private int CFfrequency;
public CharacterFrequency(char ch)
{
CFCharacter = ch;
}
public char getCharacter(char currentCharacter)
{
return CFCharacter;
}
public char setCharacter(char currentCharacter)
{
this.CFCharacter = currentCharacter;
return currentCharacter;
}
public int getFrequency(int currentFrequency)
{
return CFfrequency;
}
public int setFrequency(int currentFrequency)
{
return currentFrequency;
}
public void increment()
{
CFfrequency++;
}
public bool Equals()
{
return true;
}
public string ToString()
{
return CFCharacter.ToString();
}
}
}

Add a comment
Know the answer?
Add Answer to:
use c# visual studio Design a program that reads in an ASCII text file (provided) and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT