第1关:结构函数

任务描述

我们经常在网上购买书籍,书籍一般具有几个固定的属性,比如书籍的作者、出版年份、价格、书名等。

任务要求:使用结构定义书籍及其成员。使用成员函数返回所有信息。

测试说明

测试过程:

  • 平台将编译用户补全后代码,并根据程序的输出判断程序是否正确。

以下是测试样例:

测试输入:

预期输出:

author:Cixin Liu,price:40,yearOfPublication:2006,bookeName:The three body problem

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace H1
{

    class Program
    {
        /********** Begin *********/
		struct book
        {
            public string author;
            public string bookName;
            public double price;
            public int yearOfPublication;
            public void setAuthor(string s)
            {
                author = s;
            }

            public void setBookName(string s)
            {
                bookName = s;
            }

            public void setPrice(double s)
            {
                price = s;
            }

            public void setYearOfPublication(int s)
            {
                yearOfPublication = s;
            }

            public string getInformation()
            {
                string info = "author:" + author + ",price:" + price + ",yearOfPublication:" + yearOfPublication
                    + ",bookeName:" + bookName;
                return info;
            }
		}
        /********** End *********/

        static void Main(string[] args)
        {
            book orderBook = new book();

            orderBook.setAuthor("Cixin Liu");
            orderBook.setBookName("The three body problem");
            orderBook.setPrice(40);
            orderBook.setYearOfPublication(2006);

            Console.WriteLine(orderBook.getInformation());

        }
    }
}

  

posted @ 2020-03-23 21:45  青衫客36  阅读(240)  评论(0编辑  收藏  举报