zoukankan      html  css  js  c++  java
  • 第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());
    
            }
        }
    }
    

      

  • 相关阅读:
    python 参数化之读取写入yaml文件
    python实现对列表进行模糊查询
    通过UI自动化获取登录cookie,进行接口自动化测试
    Node.js初学
    Jquery 滚动到指定容器的位置,一行解决
    代码神兽护体
    React井字棋改进需求实现
    工作流开发流程
    call、apply和bind的学习
    call、apply和bind的学习
  • 原文地址:https://www.cnblogs.com/mjn1/p/12555345.html
Copyright © 2011-2022 走看看