12th Time Assignment

Source: Internet
Author: User

1, the definition of the structure of the type student, including the number, name, age, gender, telephone, department, grades and other information.

#include <stdio.h>structstudent{Charsno[Ten]; Charname[ -]; Charsex[Ten]; Charphone[ -]; intAge ;};intMain () {student S1=    {        "160809314",        "Liuziye",        "?",        "13716445586",          +    }; printf ("%s\n%s\n%s\n%s\n%d\n", S1.sno,s1.name,s1.sex,s1.phone,s1.age); return 0;}

2. Use the FSCANF and fprintf statements to copy the student information stored in the Input.txt file into the Output.txt file.

#include <stdio.h>#include<stdlib.h>structstudent{Charsno[Ten]; Charsname[ -]; intAge ;};intMain () {inti; Student class3[ to]; FILE*fp=fopen ("D:\\input.txt","R"); FSCANF (FP,"%s%s%d",class3[i].sno,class3[i].sname,&class3[i].age); printf ("%s\n%s\n%d\n", Class3[i].sno,class3[i].sname,class3[i].age); return 0;}

3, the implementation of the "Student management system" in the first menu "Add Student Information" module function, that is, when the user selects the "Add Student Information" menu, prompting the user to enter the student's school number, name, age and other information, and add the input information to the Student.txt file.

#include <stdio.h>structstudent{Charsno[ -]; Charname[Ten]; intAge ;}voidAdd () {studnt class3; Chari; FILE*fp=fopen ("D:\\student.txt","A +"); printf ("Please enter the number of the study:"); scanf ("%s", Class3.sno); printf ("Please enter your name:"); scanf ("%s", Class3.name); printf ("Please enter your age:"); scanf ("%d",&class3.age); fprintf (FP,"%s%s%d\n", Class3.sno,class3.name,class3.age); printf ("Student Information completed successfully, whether to continue to fill in:"); scanf ("%s",&i);  Do{printf ("Please enter the number of the study:"); scanf ("%s", Class3.sno); printf ("Please enter your name:"); scanf ("%s", Class3.name); printf ("Please enter your age:"); scanf ("%d",&class3.age); fprintf (FP,"%s%s%d\n", Class3.sno,class3.name,class3.age); printf ("Student Information completed successfully, whether to continue to fill in: (yes/no)"); scanf ("%s",&i); }     while(i=='Yes');}intMain () {printf ("Student Management System"); printf ("1. Fill in Student information"); printf ("2. Other"); intJ; if(j==1) Add (); return 0; } 

Because the last class did not go, so this homework is by asking classmates, see the picture of the teacher's class written. The second and third questions are wrong, but I do not understand.

——————————————————————————————————————-------------------last week's homework to pay ——————————————————————————————————————————————— ————————————————

1. Define the function void sum (int *p) To sum all the elements in a given array A and print out the sum of the outputs.

#include <stdio.h>//sumvoidSumint*p) {    inta[Ten]; printf ("Please enter a 10 integer: \ n"); inti,sum=0; P=&a[0];  for(i=0;i<Ten; i++) {sum=sum+*p; } printf ("integer and is:%d", sum); }intMain () {int*p;    SUM (p); return 0;} 

2. Use pointers to implement functions: Read 5 strings (or 5 characters) and output the 5 strings in order from small to large.

#include <stdio.h>intMain () {inti,a[Ten],n,m; printf ("Please enter the value of N: \ nthe"); scanf ("%d",&N);  for(i=0; i<n;i++) scanf ("%d",&A[i]);  for(i=0; i<n/2; i++) {m=A[i]; A[i]=a[n-1-i]; A[n-1-i]=m; }     for(i=0; i<n;i++) printf ("%d", A[i]); return 0; }

3. Use dynamic memory allocation to create a storage space of 10 int, which is initialized by the user from the keyboard input data, and the output space content is printed.

#include <stdio.h>#include<string.h>#include<stdlib.h>voidFsort (intA[],intn);intMain () {Char*p[5]; Charstr[ -]; scanf ("%s", str); intI=0;  while(str[0]!='#') {P[i]=(Char*)malloc(sizeof(Char)*strlen (str));        strcpy (P[I],STR); scanf ("%s", str); I++; }    intJ;  for(j=0; j<i;j++) printf ("%s", P[j]); return 0;}

The pointer to me is a bit difficult, so-so-write, not very clear.

12th Time Assignment

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.