鲤Bubble。o O 2023-09-28 15:12 采纳率: 60%
浏览 4

分析代码问题,在写实验报告,不会写分析

有没有学霸会分析代码的,我在写实践报告,不会写了

img

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;


namespace shiyan3_1

{

class Card

{

private string title, author;

private int total;

public Card()

{

title = "";author = "";

total = 0;

}

public Card (string title,string author,int total)

{

this.total = total;

this.author = author;

this.title = title;

}

public void store(ref Card card)

{

title = card.title;author = card.author;total = card.total;

}

public void show()

{

Console.WriteLine("Title:{0},Autho:{1},Tatal:{2}", title, author, total);

}

public string Title

{

get { return title; }

set { title = value; }

}

public string Author

{

get { return author; }

set { author = value; }

}

public int Total

{

get { return total; }

set { total = value; }

}

}

class shiyan3_1

{

static void Main(string[] args)

{

shiyan3_1 T = new shiyan3_1();

Card[] books;

int[] index;

int i, k;

Card card = new Card();

Console.Write("请输入需要入库的图书总数:");

string sline = Console.ReadLine();

int num = int.Parse(sline);

books = new Card[num];

for (i = 0; i < num; i++)

books[i] = new Card();

index = new int[num];

for(i=0;i< num;i++)

{

Console.Write("请输入书名:");

card.Title = Console.ReadLine();

Console.Write("请输入作者:");

card.Author = Console.ReadLine();

Console.Write("请输入入库量:");

sline = Console.ReadLine();

card.Total = int.Parse(sline);

books[i].store(ref card);

index[i] = i;

}

Console.Write("请选择按什么关键字排序(1.按书名,2.按作者,3.按入库量)");

sline = Console.ReadLine();

int choice = int.Parse(sline);


switch (choice)

{

case 1:

T.sortTitle(books, index);

break;

case 2:

T.sortAuthor(books, index);

break;

case 3:

T.sortAuthor(books, index);

break;

}

for (i = 0; i < num; i++)

{

k = index[i];

(books[k]).show();

}

Console.Read();

}

void sortTitle(Card[] book, int[] index)

{

int i, j, m, n, temp;

for (m = 0; m < index.Length - 1; m++)

for (n = 0; n < index.Length - m - 1; n++)

{

i = index[n]; j = index[n + 1];

if (String.Compare(book[i].Title, book[j].Title) > 0)

{

temp = index[n]; index[n] = index[n + 1]; index[n + 1] = temp;


}

}

}

void sortAuthor(Card[] book, int[] index)

{

int i, j, n, m, temp;

for (m = 0; m < index.Length - 1; m++)

for (n = 0; n < index.Length - m - 1; n++)


{

i = index[n]; j = index[n + 1];

if (String.Compare(book[i].Title, book[j].Title) > 0)

{

temp = index[n]; index[n] = index[n + 1]; index[n + 1] = temp;


}

}

}

void sortTolal(Card[] book, int[] index)

{

int i, j, m, n, temp;

for (m = 0; m < index.Length - 1; m++)

for (n = 0; n < index.Length - m - 1; n++)


{

i = index[n]; j = index[n + 1];

if (book[i].Total > book[j].Total)

{

temp = index[n]; index[n] = index[n + 1]; index[n + 1] = temp;

}

}


}

}

}


img

  • 写回答

2条回答 默认 最新

  • threenewbee 2023-09-28 15:30
    关注

    代码不要写一行就空一行的,该有缩进的加上缩进。
    题目要求你做成带有界面的,可是你现有的代码是字符模式的。
    这些都要改进。

    评论

报告相同问题?

问题事件

  • 修改了问题 9月28日
  • 修改了问题 9月28日
  • 创建了问题 9月28日