我已经尝试了一些方法来修复错误,我似乎无法想出这个,我会非常感谢任何帮助.错误在Triangle和Square类中,Triangle中的错误是"不实现GeometricFigure的继承抽象成员"和"没有找到合适的方法来覆盖"而Square只是"找不到合适的方法来覆盖"错误.
namespace ShapesDemo
{
class Program
{
static void Main(string[] args)
{
Rectangle rec = new Rectangle(8,10);
Square squ = new Square(11, 12);
Triangle tri = new Triangle(10, 20);
Console.WriteLine("Computed area is {0}" + "\n\n" + "Computed Triangle is: {1}" + "\n", squ.ComputeArea(rec.Area), tri.ComputeArea(rec.Area));
}
}
abstract class GeometricFigure
{
public decimal _height, _width, _area;
public decimal Height
{
get { return _height; }
set { _height = value; }
}
public decimal Width
{
get { return _width; } …Run Code Online (Sandbox Code Playgroud) 我正在研究一个问题,即创建一个程序来获取文件的用户输入,然后在文件中删除用户指定的字符串.我不确定如何从我所拥有的(下面)到问题所要求的内容.一如既往,非常感谢任何和所有的帮助.
def main():
outfile = open(input("Enter a file name: "), "a")
string = input("Enter the string to be removed: ")
for string in outfile.readlines():
string = string.replace(string, "")
outfile.close()
print("Done")
main()
Run Code Online (Sandbox Code Playgroud)
我采取了其中一个建议,并尝试让它工作,但正如我在下面的评论中所说,下面的代码不会返回错误,它会创建一个空文件.我错过了将新文件作为删除字符串的旧文件而丢失的内容?
def main():
inpath = input("Enter an input file: ")
line = input("Enter what you want to remove: ")
outpath = input("Enter an output file: ")
with open(inpath, "r") as infile, open(outpath, "w") as outfile:
for line in infile:
outfile.write(line.replace(line, "") + "\n")
print("Done.")
main()
Run Code Online (Sandbox Code Playgroud) 我不确定为什么,但是当我把断点放进去并逐步执行我的代码时,每个属性都返回null或0,当它们应该是我放在main中的值时,我疯狂的类的实例.
这是我的主要
namespace DemoJobs
{
class Program
{
static void Main(string[] args)
{
string desc;
decimal rate, time, total;
Job job1 = new Job("Pour Driveway", 8m, 50.00m);
Job job2 = new Job("Instal New Windows", 18m, 120m);
Job job3 = job1 + job2;
Console.WriteLine("The {0} job will take {1} hours, costing {2} per hour with a total of {3}",
job1.Description, job1.Time, job1.Rate.ToString("C"), job1.Total.ToString("C"));
Console.WriteLine("The {0} job will take {1} hours, costing {2} per hour with a total of {3}",
job2.Description, job2.Time, …Run Code Online (Sandbox Code Playgroud)