2018 on C language Programming (Advanced) Jobs-2nd time jobs

Source: Internet
Author: User
Tags array length

Job Requirements One:

Job requirements Two: 6-7 remove numeric characters from a string

1. Design Ideas

(1) Main description algorithm:

The first step: according to the function interface definition and requirements to realize the subject to delete all numeric characters in a string

Step Two: First define an array, I and M. In the FOR Loop statement, if * (s+i) is output between 0 and 9, the execution continues.

Step three: Until * (s+m) = ' + ' End

(2) Flowchart:

Main function:

Call function Delnum:

2. Experiment Code:

voidDelnum (Char*1) {        inti,m=0;  for(i=0; * (s+i)! =' /'; i++)        {            if(* (s+i) >='0'&&* (s+i) <='9')            {            }Else            {                * (s+m) =* (s+i); M++; }        }        * (s+m) =' /'; }    

3. Problems encountered during commissioning and solutions

The problem encountered with the 1:IF statement has an error, and the number is not represented by single quotation marks.

Correction: The error will not be followed by quotation marks.

The problem encountered in the judgment condition of the 2:for statement, equals and does not equal the condition to get reversed.

Correction method: should be * (s+i)! = ' + '

6-8 count the number of times the substring has occurred in the parent string:

1. Design Ideas

Main description algorithm:

The first step: according to the definition and requirements of the function interface to write a function, the function can be counted as a string length of 3 in another string occurrences of the number of times.

Step Two: First define an array of two char types, each of which is the input string and the string that requires statistics.

The third step: pass through the pointer, call the FUN function, using the FOR loop and if statement to determine if * (str+i)! = ' \ "is established, and if the items are established, then count++, otherwise do not.

Fourth step: Return the main function, the number of output occurrences.

2. Experiment Code:

intFunChar*STR,Char*substr) {        intI,count=0;  for(i=0; * (str+i)! =' /'; i++)        {            if(* (str+i) ==*(SUBSTR)) {                if(* (str+i+1) ==* (substr+1))                {                    if(* (str+i+2) ==* (substr+2) ) {count++; }                }            }        }        returncount; }

3. Problems encountered during commissioning and solutions:

Problem 1: The Case of * (str+i)! = ' \ "In the For statement is judged as * (str+i) = ' + ', resulting in a compile answer error

Correct method: Add a "! "Symbol, run successfully.

Problem 2: The calling function is not returned to the main function.

Correction Method: Writes return count to the program and compiles successfully.

6-9 the remaining characters in the string, except for the kinsoku characters, are sorted in descending order:

1. Design ideas:

Main description algorithm:

The first step: according to the definition and requirements of the function interface to write a function fun, the string in addition to the first, the remainder of the characters in descending order.

Step Two: First define an array of type char and store the input string.

The third step: Pass the pointer, call the fun function, the character pointer refers to the string in addition to the first, trailing characters in descending order.

Fourth step: Return the main function, output S.

2. Experiment Code;

intFunChar*s,intnum) {         inti,m,n,temp;  for(i=1; i<num-2; i++) {n=i;  for(m=i+1; m<num-1; m++)             {                 if((* (S+n)) < (int) (* (s+m)) {n=m; }             }            if(n!=i) {temp=* (S+i); * (S+i) =* (s+n); * (s+n) =temp; }        }         return 0; }

3. Problems encountered during commissioning and solutions:

Problems encountered: Do not understand why to use the i<num-2 in the For loop

Correction method: Look at the content of the semester, and asked the students, solve the problem.

7-1 Output Student Results:

1. Design ideas:

Main description algorithm

The first step: according to the function interface definition and requirements to know the subject according to the input students ' achievements, statistics and output students ' average performance, the highest score and the lowest score.

The second step: first define the number of students, average, maximum, minimum value. Assign value to n, define pointer variable p as floating point, request continuous memory space by malloc function n

The third step: input n Data assignment to * (p+i), calculate sum, through the for loop to find the maximum score assigned to max, the minimum value assigned to min, the final output average highest score and the lowest score.

2. Experiment Code:

#include <stdio.h>intMain () {intI,n; floatsum=0, Average,max,min; scanf ("%d",&N); float*p= (float*)malloc(n);  for(i=0; i<n;i++) {scanf ("%f", (p+i)); Sum=sum+* (p+i); } min=* (p+0); Max=* (p+0);  for(i=0; i<n;i++)    {        if(Min>* (p+i)) {min=* (p+i); }        if(Max<* (p+i) {max=* (p+i); }} printf ("average =%.2f\n", sum/n*1.0); printf ("max =%.2f\n", Max); printf ("min =%.2f\n", Min); return 0;}

3. Problems encountered during commissioning and solutions:

Problem encountered: Because it was not used average, but in the output when used, resulting in a wrong answer.

Correction method: The average should be converted to the average represented by sum.

7-1 calculation of worker's salary:

1. Design ideas;

(1) Main description algorithm:

The first step: the subject is to use the structure of the way to calculate wages. It is necessary to use structural struct ...

Step Two: First define the structure struct staff in front of the main function, which contains the name and salary information.

Step three: Define the struct variable struct staff S1 in the main function, enter and print payroll information in the For loop, such as S1.num. Through calculation, the output of staff wages.

(2) Flowchart:

2. Experiment Code;

#include <stdio.h>//#include <stdlib.h> structStaff {Charname[Ten]; floatB,f, out; floatreality;}; intMain () {intI,n; structStaff s1,reality; scanf ("%d",&N);  for(i=1; i<=n;i++) {scanf ("%s%f%f%f", S1.name,&s1.b,&s1.f,&s1. out); S1.reality= (s1.b+s1.f-s1. out); printf ("%s%.2f\n", s1.name,s1.reality); }         return 0; }

3. Problems encountered during commissioning and solutions:

Problem 1: Write printf ("%s%.2f\n", s1.name,s1.reality) out of the For loop, and the result is an edge input edge output, the answer does not meet the requirements

FIX: Write printf ("%s%.2f\n", s1.name,s1.reality) out of the for loop and compile successfully.

Problem 2: The symbols in the formula are used incorrectly.

Correction method: Carefully read the formula, compile successfully.

7-2 calculate the average score;

1. Design ideas:

Main description algorithm:

The first step: the subject is required to use the structure of the way to calculate student performance. Use to struct struct ...

Step Two: First define the struct struct student in front of the main function, which contains the name and the student's basic information.

Step three: Define the array structure variable struct student s1[n] in the main function, enter and print the student's basic information in the For loop. Calculates the sum. Calculates the average. In another for loop, compare the results of each person to the average and output the student information that is less than the average.

2. Experiment Code:

#include <stdio.h>//#include <stdlib.h>structstudent{Charnum[6]; Charname[Ten]; intgrade;};intMain () {Doubleaverage; intn,i,sum=0; scanf ("%d",&N); structstudent S1[n];  for(i=0; i<n;i++) {scanf ("%s%s%d",s1[i].num,s1[i].name,&S1[i].grade); Sum=sum+S1[i].grade; } Average=sum/N; printf ("%.2f\n", average);  for(i=0; i<n;i++)   {        if(average>S1[i].grade) {printf ("%s%s\n", S1[i].name,s1[i].num); }    }       //System ("pause");       return 0;} 

3. Problems encountered during commissioning and solutions:

Problem encountered: A segment error occurred while defining the array.

How to correct: After looking at the discussion panel, we understand that if the defined array length is insufficient, a segment error occurs.

6-1 statistics of Students by grade:

1. Design ideas:

(1) Main description algorithm

The first step is to ask for a simple function that sets its rank according to the student's score and counts the number of failed students by means of a structure array pointer.

The second step: define struct type variables, struct named student, members in struct include integer num, character array name[20], integral type score and character grade. Defines the struct-body variable named stu[10],*ptr.

Step three: Call the Set_grade function and return the function to count. In the Set_grade function, a for loop is adopted to determine if the P->score is <60, and the m++ is established, otherwise it is not executed. Then judge the rank and return the value of M. The number of outputs, the number of each person, name, rank.

(2) Flowchart:

2. Experiment Code:

intSet_grade (structStudent *p,intN) {    inti,m=0;  for(i=0; i<n;i++,p++)    {        if(p->score< -) {m++; }        if((p->score>= -) && (p->score<= -) ) {p->grade ='A'; }Else if((p->score>= -) && (p->score<= -) ) {p->grade ='B'; }Else if((p->score>= -) && (p->score<= the) ) {p->grade='C'; }Else{p->grade='D'; }    }    returnm;} 

3. Problems encountered during commissioning and solutions:

Problem 1: When you do else, there is no statement that gives another case.

Correction method: To give a judgment statement of else if after for.

6-2 structure array sorted by total:

1. Design ideas:

Main description algorithm

The first step: the subject is to use the structure of array pointers to achieve the sum of scores from high to low to sort the data.

The second step: there are two calling functions, 1. Call the Calc function, and in the Calc function, find the value of the sum of the respective fractions (p+i)->sum by two for loops ; 2. Call the sort function, define integer i,j,m in the sort function, define struct variables, variable named temp, sort this set of data by selecting Sort method

The third step: the number of the output member, name, the scores and total score of each section.

2. Experiment Code:

voidCalcstructStudent *p,intN) {  structstudent sum; inti,j=0;  for(i=0; i<n;i++)    {       for(j=0;j<3; j + +) (P+i)->sum= (p+i)->sum+ (p+i),Score[j]; }}voidSortstructStudent *p,intN) {    inti,j,m; structStudent temp;  for(i=0; i<n-1; i++) {m=i;  for(j=i;j<n;j++)        {            if((p+m)->sum) < ((P+J)sum)) {m=J; }        }        if(m!=i) {temp=* (p+i); * (p+i) =* (p+m); * (p+m) =temp; }    }}

3. Problems encountered during commissioning and solutions:

Problems encountered: The array score is written as a single array when calculating fractions

Correction method: Should be changed to SCORE[J].

Learning Summary and Progress:

1. What have you learned from the knowledge points learned in the two weeks? (The knowledge points that can be recorded for each job title) which have not been learned?

These two weeks have mainly studied the structure and the application of the structure. The first thing to learn is the concept and definition of the structure, learning that the structure should be defined outside the main function, and in the application of the definition of structural variables. After learning the structure array, and the combination of structure and pointer, we learned an important structure pointer reference format p-> struct member name.

In the first two PTA when feel can also understand, but the third time feel some difficulty, prove or master not skilled, to more practice.

Reviews classmate:

Sun Mingxian: http://www.cnblogs.com/sun031915/p/8687824.html

Zhang Cenyue: http://www.cnblogs.com/zxy980612/p/8696690.html

Wu Xiaoming: http://www.cnblogs.com/gu-an-cheng-wxm/p/8697025.html

Study Progress Chart:

2018 on C language Programming (Advanced) Jobs-2nd time jobs

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.