其他分享
首页 > 其他分享> > 第1关:结构函数

第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());

        }
    }
}

  

标签:string,结构函数,public,yearOfPublication,orderBook,using,void
来源: https://www.cnblogs.com/mjn1/p/12555345.html