1 winter operations program title

Job Description Detail
This work belongs courses 2020 Object-Oriented Programming
Where the job requires Object-oriented programming winter operations 1
The target job Complete programming problems, realize Chinese programming.
Text of the job Object-Oriented Programming 1 winter operations program title
Other references no

Third, the programming problem

(Please use the C or C ++ language to complete the following topics):
Chinese culture is profound, starting from Changjei creation, Chinese characters has been passed down to this day. When we lamented the long history of Chinese characters, but also can not help feeling, why not a programming language using Chinese characters?
Chinese characters can not really programming? Recently classical programming a fire, I have a number. Said III. Name, called "armor." This unpretentious variable definition is certainly not thousands of years of Chinese culture in the development of a wonderful work.
Today, Wang students think, classical vernacular that can be programmed to do? He found you, let you help him.

  • Programming requires
    the preparation of a program, the result of input to meet the following syntax requirements of a piece of text output operation.
    Variable Definition: an integer equal to zero wallet
    arithmetic (adder): Purse increased by 4
    operation (subtraction): Purse reduced by four
    outputs: a look wallet

  • Sample
    input:
    integer equal to zero wallet
    purse increased by 4
    purse decrease three
    look wallet
    output:
    a

  • Note:
    O GBK encoding both cases, the text is recommended vscode switched GBK encoding.
    The following figures will only be zero 12,345,678 ninety.

  • Programming questions require:
    1. Read the question, extract the required subject.
    2. break down demand, the demand broken down into several modules you feel less relevant.
    3. Each module thinking how to write, start writing from simple modules.
    4. access to information for problem will not.
    The test cases for each module.
    Each step above under 6. detailed records and write in a blog.
    7. not required to do it completely, but requires detailed records.
    8. The recommended length of less than 1,000 words blog (no code).

  • Topics requirements:
    Write a program that inputs the result of the following syntax meet the requirements of paragraph of text, output operation.
    Variable Definition: an integer equal to zero wallet
    arithmetic (adder): Purse increased by 4
    operation (subtraction): Purse reduced by four
    outputs: a look wallet

  • Decomposition demand:
    Module 1:
    According to the meaning of the questions format input
    module II:
    The Chinese are "123 ...... ten" into a digital "1,2,3 ...... 10"
    Module 3:
    Converts a number to Chinese
    Module IV :
    the Chinese of "increase, decrease, multiply, divide" to "+ - * /"

  • Thinking Solution
    Module 1: According to the meaning of the questions input format
    "integer equal to zero wallet" This line of input alone, "purse increase four" This type of loop input, to the emergence of "Look", after once again enter, break out of use cycle.
    Code:
int main()
{
    int n,p;
    char str1[100],str2[100],str3[100],str4[100];
    scanf("%s %s %s %s",&str1,&str2,&str3,&str4);
    n=zhuanhuan(str4);
    for(;;)
    {
        scanf("%s",str1);
        if(strcmp(str1,"看看")==0)
        {
            scanf("%s",str2);
            break;
         } 
            
        
        else
        {
            scanf("%s %s",str2,str3);
           p=zhuanhuan(str3);
           n=jisuan(str2,n,p); 
        }
        
    }
    zhuanhuan2(n);
    return 0;
 } 

Module II: The Chinese are "123 ...... ten" into a digital "1,2,3 ......, 10"
I do not understand how to use gbk code, the final choice of treatment with strcmp, for example: if(strcmp(str,"十")==0) return 10;but now, I have can not handle larger than the input ten, unless I resolved to add from "a" has been listed in the "nine nine", and so on later.
Code:

int zhuanhuan(char a[100])
 {
    
    if(strcmp(a,"零")==0)
    return 0;
    else if(strcmp(a,"一")==0)
    return 1; 
    else if(strcmp(a,"二")==0)
    return 2;
    else if(strcmp(a,"三")==0)
    return 3;
    else if(strcmp(a,"四")==0)
    return 4;  
    else if(strcmp(a,"五")==0)
    return 5;
    else if(strcmp(a,"六")==0)
    return 6;
    else if(strcmp(a,"七")==0)
    return 7;
    else if(strcmp(a,"八")==0)
    return 8;
    else if(strcmp(a,"九")==0)
    return 9;
    else if(strcmp(a,"十")==0)
    return 10;
 }

Module 3: Chinese convert the digital
I into the digital processing and ten or less in the case of greater than ten.

  • It is less than equal to ten converted directly output
  • In the case of greater than ten, the two-digit numbers are taken, for example: the first is three, thirty directly output, the second is 4, four outputs, the final results can be obtained thirty-four

Code:

char zhuanhuan2(int e)
 {
    int j,k;
    if(e<=10)
    {
        if(e==0)
    printf("零");
    else if(e==1)
    printf("一");
    else if(e==2)
    printf("二");
    else if(e==3)
    printf("三");
    else if(e==4)
    printf("四");
    else if(e==5)
    printf("五");
    else if(e==6)
    printf("六");
    else if(e==7)
    printf("七");
    else if(e==8)
    printf("八");
    else if(e==9)
    printf("九");
    else if(e==10)
    printf("十");
     }
    else
    {
        j=e%10;
        e=e/10;
        k=e;
         if(k==1)
    printf("一十");
    else if(k==2)
    printf("二十");
    else if(k==3)
    printf("三十");
    else if(k==4)
    printf("四十");  
    else if(k==5)
    printf("五十");
    else if(k==6)
    printf("六十");
    else if(k==7)
    printf("七十");
    else if(k==8)
    printf("八十");
    else if(k==9)
    printf("九十");
    else if(k==10)
    printf("一百");
     if(j==1)
    printf("一");
    else if(j==2)
    printf("二");
    else if(j==3)
        printf("三");
    else if(j==4)
    printf("四");  
    else if(j==5)
    printf("五");
    else if(j==6)
    printf("六");
    else if(j==7)
    printf("七");
    else if(j==8)
    printf("八");
    else if(j==9)
    printf("九");
     }
 }

Module four: the Chinese "increase, decrease, multiply, divide" to "+ - * /"
Similarly strcmp used, for example: if(strcmp(str,"乘以")==0)multiplication.
Code:

int jisuan(char b[100],int c,int d)
 {
    if(strcmp(b,"增加")==0)
    c=c+d;
    if(strcmp(b,"减少")==0)
    c=c-d;
    if(strcmp(b,"乘以")==0)
    c=c*d;
    if(strcmp(b,"除以")==0)
    c=c/d;
    return c;
 }
  • Test sample:

Module 1: Input format according to the meaning of the questions

Module II: The Chinese are "123 ...... ten" into a digital "1,2,3 ...... 10"

Module 3: convert a number to Chinese


Module IV:
The Chinese of "increase, decrease, multiply, divide" to "+ - * /"

Not any greater than the input sample ten:

  • The complete code
#include<stdio.h>
#include<string.h>
int zhuanhuan(char a[100]);
int jisuan(char b[100],int c,int d);
char zhuanhuan2(int e);
char str5[100],str6[100];
int main()
{
    int n,p;
    char str1[100],str2[100],str3[100],str4[100];
    scanf("%s %s %s %s",&str1,&str2,&str3,&str4);
    n=zhuanhuan(str4);
    for(;;)
    {
        scanf("%s",str1);
        if(strcmp(str1,"看看")==0)
        {
            scanf("%s",str2);
            break;
         } 
            
        
        else
        {
            scanf("%s %s",str2,str3);
           p=zhuanhuan(str3);
           n=jisuan(str2,n,p); 
        }
        
    }
    zhuanhuan2(n);
    return 0;
 } 
 int zhuanhuan(char a[100])
 {
    
    if(strcmp(a,"零")==0)
    return 0;
    else if(strcmp(a,"一")==0)
    return 1; 
    else if(strcmp(a,"二")==0)
    return 2;
    else if(strcmp(a,"三")==0)
    return 3;
    else if(strcmp(a,"四")==0)
    return 4;  
    else if(strcmp(a,"五")==0)
    return 5;
    else if(strcmp(a,"六")==0)
    return 6;
    else if(strcmp(a,"七")==0)
    return 7;
    else if(strcmp(a,"八")==0)
    return 8;
    else if(strcmp(a,"九")==0)
    return 9;
    else if(strcmp(a,"十")==0)
    return 10;
 }
 char zhuanhuan2(int e)
 {
    int j,k;
    if(e<=10)
    {
        if(e==0)
    printf("零");
    else if(e==1)
    printf("一");
    else if(e==2)
    printf("二");
    else if(e==3)
    printf("三");
    else if(e==4)
    printf("四");
    else if(e==5)
    printf("五");
    else if(e==6)
    printf("六");
    else if(e==7)
    printf("七");
    else if(e==8)
    printf("八");
    else if(e==9)
    printf("九");
    else if(e==10)
    printf("十");
     }
    else
    {
        j=e%10;
        e=e/10;
        k=e;
         if(k==1)
    printf("一十");
    else if(k==2)
    printf("二十");
    else if(k==3)
    printf("三十");
    else if(k==4)
    printf("四十");  
    else if(k==5)
    printf("五十");
    else if(k==6)
    printf("六十");
    else if(k==7)
    printf("七十");
    else if(k==8)
    printf("八十");
    else if(k==9)
    printf("九十");
    else if(k==10)
    printf("一百");
        if(j==0)
    printf("零");
    else if(j==1)
    printf("一");
    else if(j==2)
    printf("二");
    else if(j==3)
    printf("三");
    else if(j==4)
    printf("四");  
    else if(j==5)
    printf("五");
    else if(j==6)
    printf("六");
    else if(j==7)
    printf("七");
    else if(j==8)
    printf("八");
    else if(j==9)
    printf("九");
     }
 }
 int jisuan(char b[100],int c,int d)
 {
    if(strcmp(b,"增加")==0)
    c=c+d;
    if(strcmp(b,"减少")==0)
    c=c-d;
    if(strcmp(b,"乘以")==0)
    c=c*d;
    if(strcmp(b,"除以")==0)
    c=c/d;
    return c;
 }

Guess you like

Origin www.cnblogs.com/2002ljy/p/12233531.html
Recommended