Dinny
Dinny
CC#
Created by Dinny on 12/4/2023 in #help
Fixing unscrambling file
No description
6 replies
CC#
Created by Dinny on 12/4/2023 in #help
input file error
when reading numbers in my input file, i convert them to integers and assign specific numbers to a variable such as
uint x = Convert.ToUInt32(nextItem[0]);
uint y = Convert.ToUInt32(nextItem[1]);
uint z = Convert.ToUInt32(reader.ReadLine());
uint x = Convert.ToUInt32(nextItem[0]);
uint y = Convert.ToUInt32(nextItem[1]);
uint z = Convert.ToUInt32(reader.ReadLine());
but i keep getting an error saying "'Input string was not in a correct format.'" i am unsure how to fix this because the input file is automatically a string, but converting it to an int is causing an error. I normally convert this way and have not had an issue
222 replies
CC#
Created by Dinny on 12/3/2023 in #help
Adding red, green, and blue pixels into a list after being red form the input file
using System;
using System.IO;
using System.Collections.Generic;

namespace Module_12
{

public class Program
{
static void Main(string[] args)
{
// Open the input and output file.
FileStream inputFile = new("ScrambledFlag.ppm", FileMode.Open, FileAccess.Read);
StreamReader reader = new(inputFile);
FileStream outputFile = new("UnscrambledFlag.ppm", FileMode.Create, FileAccess.Write);
StreamWriter writer = new(outputFile);

//read header of input file
while (!reader.EndOfStream)
{

string? nextLine = reader.ReadLine();

if ( nextLine != null )
{
string[] nextItem = nextLine.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
if (nextItem.Length == 0) { continue; }

//reading header and converting to int
string? p = reader.ReadLine();
int x = Convert.ToInt32(nextItem[0]);
int y = Convert.ToInt32(nextItem[1]);
int z = Convert.ToInt32(reader.ReadLine());

List<Pixel> pixels = new List<Pixel>(x * y);

for (int i = 0; i < pixels.Count; i++)
{
int first;
int second;
int third;


pixels.Add();
}



//writing header to output file
//write header to output file
writer.WriteLine(p);
}
}

}
}
}
using System;
using System.IO;
using System.Collections.Generic;

namespace Module_12
{

public class Program
{
static void Main(string[] args)
{
// Open the input and output file.
FileStream inputFile = new("ScrambledFlag.ppm", FileMode.Open, FileAccess.Read);
StreamReader reader = new(inputFile);
FileStream outputFile = new("UnscrambledFlag.ppm", FileMode.Create, FileAccess.Write);
StreamWriter writer = new(outputFile);

//read header of input file
while (!reader.EndOfStream)
{

string? nextLine = reader.ReadLine();

if ( nextLine != null )
{
string[] nextItem = nextLine.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
if (nextItem.Length == 0) { continue; }

//reading header and converting to int
string? p = reader.ReadLine();
int x = Convert.ToInt32(nextItem[0]);
int y = Convert.ToInt32(nextItem[1]);
int z = Convert.ToInt32(reader.ReadLine());

List<Pixel> pixels = new List<Pixel>(x * y);

for (int i = 0; i < pixels.Count; i++)
{
int first;
int second;
int third;


pixels.Add();
}



//writing header to output file
//write header to output file
writer.WriteLine(p);
}
}

}
}
}
9 replies
CC#
Created by Dinny on 11/21/2023 in #help
Generic Interfaces
I am having trouble implementing a method in my class that I derived from my Generic interface using T data type. IComparableType
using System;
using System.IO;

namespace Modeul_11
{
public interface IComparableType<T>
{
public int CompareTo(T other);
}

}
using System;
using System.IO;

namespace Modeul_11
{
public interface IComparableType<T>
{
public int CompareTo(T other);
}

}
Shape
using Modeul_11;
using System;
using System.IO;

namespace Module_11
{

//Abstract class that extends the interface
public abstract class Shape : IComparableType<Shape>
{
public abstract double Area();

public abstract string WhatAmI();

public int CompareTo(Shape other)
{
//if shape1 is less than shape 2, return -1
// if shape 1 is greater than shape 2, return 1
//if shape 1 and shape 2 are equal, return 0
return 1; //FIXME
}


}
}
using Modeul_11;
using System;
using System.IO;

namespace Module_11
{

//Abstract class that extends the interface
public abstract class Shape : IComparableType<Shape>
{
public abstract double Area();

public abstract string WhatAmI();

public int CompareTo(Shape other)
{
//if shape1 is less than shape 2, return -1
// if shape 1 is greater than shape 2, return 1
//if shape 1 and shape 2 are equal, return 0
return 1; //FIXME
}


}
}
23 replies
CC#
Created by Dinny on 11/12/2023 in #help
I can't figure out how to fix this error for my input file
if( nextLine != null)
{
string[] nextItem = nextLine.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
if (nextItem.Length == 0) { continue; }

//BOXCAR
if (nextItem[0].Equals("Box"))
{
//do something
boxcar = Convert.ToInt32(nextItem[1], nextItem[2], nextItem[3]);
writer.WriteLine(boxcar.Volume());
}

//TANKCAR
if (nextItem[0].Equals("Tank"))
{
//do something
tankcar = Convert.ToInt32(nextItem[1], nextItem[2]);
writer.WriteLine(tankcar.Volume());
}

//REFRIGERATOR
if (nextItem[0].Equals("Refrigerator"))
{
//do something
refrig = Convert.ToInt32(nextItem[1], nextItem[2], nextItem[3], nextItem[4]);
writer.WriteLine(refrig.Volume());
}
}
if( nextLine != null)
{
string[] nextItem = nextLine.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
if (nextItem.Length == 0) { continue; }

//BOXCAR
if (nextItem[0].Equals("Box"))
{
//do something
boxcar = Convert.ToInt32(nextItem[1], nextItem[2], nextItem[3]);
writer.WriteLine(boxcar.Volume());
}

//TANKCAR
if (nextItem[0].Equals("Tank"))
{
//do something
tankcar = Convert.ToInt32(nextItem[1], nextItem[2]);
writer.WriteLine(tankcar.Volume());
}

//REFRIGERATOR
if (nextItem[0].Equals("Refrigerator"))
{
//do something
refrig = Convert.ToInt32(nextItem[1], nextItem[2], nextItem[3], nextItem[4]);
writer.WriteLine(refrig.Volume());
}
}
114 replies
CC#
Created by Dinny on 11/10/2023 in #help
can someone help me with my abstract class
I've created my abstract classes and no we can't make instances of them, but i keep getting errors even after following youtube videos to the t. here's my first file using abstract classes
namespace Module_9
{
public abstract class RailroadCar
{
//data fields
protected double length;

//constr
protected RailroadCar(double length = 0.00)
{
SetLength(length);
}

//GETTERS
/** Returns length of solid.
@return: solid length
*/
public double GetLength(double length) { return length; }

/** Updates length of solid.
@return: updated length.
*/
//SETTERS
public void SetLength(double length) { this.length = length;}

/** Calculates the volume of the solid.
@return: calculated volume of the solid
*/
public abstract double Volume();
}
}
namespace Module_9
{
public abstract class RailroadCar
{
//data fields
protected double length;

//constr
protected RailroadCar(double length = 0.00)
{
SetLength(length);
}

//GETTERS
/** Returns length of solid.
@return: solid length
*/
public double GetLength(double length) { return length; }

/** Updates length of solid.
@return: updated length.
*/
//SETTERS
public void SetLength(double length) { this.length = length;}

/** Calculates the volume of the solid.
@return: calculated volume of the solid
*/
public abstract double Volume();
}
}
51 replies
CC#
Created by Dinny on 10/29/2023 in #help
I am unaware on how to fix this conversion error
it's saying i can't convert from string to int, though I am unsure why when i used the string.format method to represent my int variable ID as a string and display it in my output file. I have three separte files for a regular user logging in, an administrator, and thena file to put the whole program together. here is admin and the full program since that is where the issue lies
using System;
using System.Globalization;
using System.IO;


namespace LogIn
{
public class Administrator : RegularUser
{
//data fields
private int ID;


public Administrator(int ID = 0, string userName = " ") : base(userName)
{
//data fields
this.ID = ID;
}

//GETTER
/**
Returns the ID of the admin
@return: admin's ID
*/
public int GetID() { return ID; }


//SETTERS
/**
Returns an updated ID number
@return: admin's updated ID number
*/
public void SetID(int ID) { this.ID = ID; }

//sign-in method
public new static void SignIn(string dateAndTime, StreamWriter writer)
{
writer.WriteLine("signed in @ {1}", dateAndTime);
}

//sign out method
public new static void SignOut(string dateAndTime, StreamWriter writer)
{
writer.WriteLine("signed out @ {1}", dateAndTime);
}


/** Returns the user's username and ID in string format and whether they've signed in/out
@return: a string representing who signed in/out along with ther ID #
*/
public override string Stringify()
{
return string.Format("({1}) ", base.Stringify(), GetID());
}

public override string Stringify2()
{
return string.Format("({1}) ", base.Stringify2(), GetID());
}


}


}
using System;
using System.Globalization;
using System.IO;


namespace LogIn
{
public class Administrator : RegularUser
{
//data fields
private int ID;


public Administrator(int ID = 0, string userName = " ") : base(userName)
{
//data fields
this.ID = ID;
}

//GETTER
/**
Returns the ID of the admin
@return: admin's ID
*/
public int GetID() { return ID; }


//SETTERS
/**
Returns an updated ID number
@return: admin's updated ID number
*/
public void SetID(int ID) { this.ID = ID; }

//sign-in method
public new static void SignIn(string dateAndTime, StreamWriter writer)
{
writer.WriteLine("signed in @ {1}", dateAndTime);
}

//sign out method
public new static void SignOut(string dateAndTime, StreamWriter writer)
{
writer.WriteLine("signed out @ {1}", dateAndTime);
}


/** Returns the user's username and ID in string format and whether they've signed in/out
@return: a string representing who signed in/out along with ther ID #
*/
public override string Stringify()
{
return string.Format("({1}) ", base.Stringify(), GetID());
}

public override string Stringify2()
{
return string.Format("({1}) ", base.Stringify2(), GetID());
}


}


}
108 replies
CC#
Created by Dinny on 10/24/2023 in #help
✅ Reading matricies to an output file
I am trying to read the data inside two matricies from an input file firstly in order to add them together and display the result to the output file. Before I get to that, I am struggling trying to get the program to read each row and column. Here's the block of code with my errors
//going through each row to get matrix numbers
while (!reader.EndOfStream)
{

nextLine = reader.ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
if (nextLine.Length == numOfColumns)
{
for (int j = 0; j < numOfColumns; j++)
{

a[rowIndex, j] = int.Parse(nextLine[j]);

}

rowIndex++;


}
}
//going through each row to get matrix numbers
while (!reader.EndOfStream)
{

nextLine = reader.ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
if (nextLine.Length == numOfColumns)
{
for (int j = 0; j < numOfColumns; j++)
{

a[rowIndex, j] = int.Parse(nextLine[j]);

}

rowIndex++;


}
}
I have a red line where it says " a[rowIndex, j] = int.Parse(nextLine[j]); and the error reads "Cannot apply indexing [] to an expression of type "Matrix.Matricies."
7 replies
CC#
Created by Dinny on 10/20/2023 in #help
Overloading "+" operator
I am adding fractions together and need to overload the plus operator, but I keep running into an error while I am building the code. Before even adding them together, he wants us to find the GCD (greatest common denom) to simplfy the fractions down before adding them together, which is where my error arises.
private void Simplify()
{
if (numerator == 0)
{

denominator = 1;
return;

}

//Finding GCD for num and denom.
uint GCD = GetGCD((uint)Math.Abs(numerator), denominator);
numerator /= (int)GCD;
denominator /= GCD;
}
private void Simplify()
{
if (numerator == 0)
{

denominator = 1;
return;

}

//Finding GCD for num and denom.
uint GCD = GetGCD((uint)Math.Abs(numerator), denominator);
numerator /= (int)GCD;
denominator /= GCD;
}
I get an error under "denominator" after the "Math.Abs(numerator)" and when dividing the denominator by the GCD
46 replies
CC#
Created by Dinny on 10/15/2023 in #help
A quick question, how do we edit the value of an attribute in an input file?
No description
114 replies
CC#
Created by Dinny on 10/14/2023 in #help
are my getters and setters correct?
Before I work on the rest of my code, please let me know if there are any errors in my getters and setters using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; public class Menu { private string dishName; private int dishType, dishPrice; //def constructor class Menu() { } //const with param public Menu(String dishName, int dishType, int dishPrice) { SetName(dishName); SetType(dishType); SetPrice(dishType); } //GETTERS / Returns the name of the dish. @return: dish name */ public void GetName() { return dishName; } / Returns the type of dish ordered. @return: returns either appetizer, entree, or dessert */ public int GetType() { return dishType; } / Returns the height of the rectangle. @return: height of the rectangle */ public interface GetPrice() { returns dishPrice; } //SETTERS / Updates name of dish. @param width: the updated dish name */ public void SetName(string dishName) { this.Name = dishName; } / Updates the type of dish. @param width: the updated dish type */ public void SetType(string dishType) { this.Type = dishType; } / Updates the type of dish. @param width: the updated dish type */ public void SetPrice(string dishPrice) { this.Price = dishPrice; } public override string ToString() { return string.Format(dishName + "(" + dishPrice + ")", GetName(), GetPrice()); } }
278 replies
CC#
Created by Dinny on 10/8/2023 in #help
❔ i don’t understand why my output file is blank
No description
3 replies
CC#
Created by Dinny on 10/8/2023 in #help
✅ input and output file help with 2d arrays
No description
1 replies
CC#
Created by Dinny on 9/16/2023 in #help
✅ c# input and output files
No description
22 replies