Question
Info 1182 Project 4a Strings, Files, Simple Class Invictus William Ernest Henley (18491903). Out of the night that covers me, Black as the pit from
Info 1182 Project 4a Strings, Files, Simple Class
Invictus
William Ernest Henley (18491903).
Out of the night that covers me,
Black as the pit from pole to pole,
I thank whatever gods maybe
For my unconquerable soul.
In the fell clutch of circumstance
I have not winced nor cried aloud.
Under the bludgeonings of chance
My head is bloody but unbowed.
Beyond this place of wrath and tears
Looms but the Horror of the shade,
And yet the menace of the years
Finds and shall find me unafraid.
It matters not how strait the gate,
How charged with punishments the scroll,
I am the master of my fate:
I am the captain of my soul
Create a folder
- Using just the ElementAt, Length, and Substring string methods and the + (concatenate) operator, write a function that accepts a string s, a start position p, and a length l, and returns s with the characters starting in position p for a length of l removed. Dont forget that strings start at position 0. Thus (abcdefghijk, 2, 4) returns abghijk. Dont use any remove or similar built-in string gadget.
- Write a function that accepts a string s and a character c and returns the number of times c occurs in s.
- Write a function that accepts a string and returns its reverse. Thus reverse(abcdef) should return fedcba. Ideally, your function does not create an extra array. Dont use any built-in reverse string gadget.
- Using the following TextFile class, read in a string t that contains the invictus.txt file provided for this assignment. To be able to read the file, it must be placed into the
/bin/debug folder right next to the .exe for the project. Apply the ToUpper string method to the string containing the contents of the textfile and then write the results out to a text file.
/****************************************************
* TextFileClass - David Beard
* reads and writes string to and from text file
* **************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO; //note that we have included System.IO
namespace textFileClassSamplier
{
class TextFileClass
{
private string fileName;
/// constructor.FilePath may be absolute or relative.
/// if relative, it is contained inside the obj sub folder.
public TextFileClass(string _fileName)
{
fileName = _fileName;
}
/// GetStringFromTextFile - dvb
/// reads
public string GetStringFromTextFile()
{
string s = "";
if(fileName.Length >0)
{
StreamReader streamReader = new StreamReader(fileName);
s = streamReader.ReadToEnd();
streamReader.Close();
}
return s;
}
/// WriteStringToTextFile - dvb
/// Writes String to textfile. Assumes " " line feeds as returned
/// from textbox.
public void writeStringToTextFile(string s)
{
if(fileName.Length >0)
{
StreamWriter file = new StreamWriter(fileName);
file.WriteLine(s);
file.Close();
}
}
}
}
Rubric:
- Tasks 25 points each.
- Style -20
- Block comment with name, date, and good sentence(s)
- Good variable names
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started