Question

You are asked to define a user-defined data type for students, that will contain the following information about a student: ID number, first name, last name, major, GPA. Your structure should be cal Student. Based on the defined structure, user name on the command line, show how you will use a loop to search for the given name within the array of 5 students. use an array to record information about 5 students. Then, given a Write a C program that will accept a user name as a string input from the user, and then determines whether or not the user name appears as one of the names in the 5 student records. Your program should prompt the user for inputs. If the name is found, your program should display the information in the students record. You may use predefined functions, such as strempo if you wish. However, this is NOT required. What to submit: (1) Hard copy of your program code(s) 2) Screen shots showing results for sample runs of the program, for at least 3 input cases
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>
#include<strings.h>

struct Student
{
char   Id_No[10];      // ID number
char   fname[20];      // first name
char   lname[20];      // last name
char   major[20];
float gpa;            // Grade point average
};

int main()
{
   struct Student s[5]; // array to record information upto 5 students
   int i;                // array index
   char usrname[20];     // to accept user name from the input device
   int flag = 0;         // flag is set one, when given user input name is found in student list
   for(i=0;i<5;i++)
    {
      printf("Enter %d student details : \n", i+1);
      printf("Enter ID number   : ");
      scanf("%s", s[i].Id_No);
      printf("Enter First name : ");
      scanf("%s", s[i].fname);
      printf("Enter Last name : ");
      scanf("%s", s[i].lname);
      printf("Enter major : ");
      scanf("%s", s[i].major);
      printf("Enter GPA : ");
      scanf("%f", &s[i].gpa);
    }

   printf("Enter a user name : ");
   scanf("%s", usrname);
   for(i=0;i<5;i++)
    {
      if ( strcasecmp(s[i].fname,usrname) == 0 || strcasecmp(s[i].lname,usrname) == 0)
       {
          printf("%s - student details found ...\n", usrname);
          printf("===============================================\n");
          printf("Student Id Number : %s\n", s[i].Id_No);
          printf("First name        : %s\n", s[i].fname);
          printf("Last name         : %s\n", s[i].lname);
          printf("Major             : %s\n", s[i].major);
          printf("GPA               : %.1f\n",s[i].gpa);
          flag=1;
          break;
       }
    }
   if( flag == 0 )
    {
       printf("%s - student information not found\n", usrname);
    }
   return 0;
}


/*

lenovo@lenovo-Vbox:~$ uname -a
Linux lenovo-Vbox 3.19.0-25-generic #26~14.04.1-Ubuntu SMP Fri Jul 24 21:16:20 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

lenovo@lenovo-Vbox:~$ cc stu.c
lenovo@lenovo-Vbox:~$ ./a.out
Enter 1 student details :
Enter ID number   : 101
Enter First name : Mars
Enter Last name : Martin
Enter major : B.Tech
Enter GPA : 4.3
Enter 2 student details :
Enter ID number   : 102
Enter First name : Duke
Enter Last name : james
Enter major : B.Com
Enter GPA : 2.0
Enter 3 student details :
Enter ID number   : 103
Enter First name : Belew
Enter Last name : kem
Enter major : B.Sc
Enter GPA : 3.3
Enter 4 student details :
Enter ID number   : 104
Enter First name : Preston
Enter Last name : paul
Enter major : B.Tech
Enter GPA : 8.4
Enter 5 student details :
Enter ID number   : 105
Enter First name : Steve
Enter Last name : jobs
Enter major : B.Sc
Enter GPA : 5.6
Enter a user name : paul
paul - student details found ...
===============================================
Student Id Number : 104
First name        : Preston
Last name         : paul
Major             : B.Tech
GPA               : 8.4
lenovo@lenovo-Vbox:~$

lenovo@lenovo-Vbox:~$ ./a.out
Enter 1 student details :
Enter ID number   : 101
Enter First name : Mars
Enter Last name : Martin
Enter major : B.Tech
Enter GPA : 4.3
Enter 2 student details :
Enter ID number   : 102
Enter First name : Duke
Enter Last name : james
Enter major : B.Com
Enter GPA : 2.0
Enter 3 student details :
Enter ID number   : 103
Enter First name : Belew
Enter Last name : kem
Enter major : B.Sc
Enter GPA : 3.3
Enter 4 student details :
Enter ID number   : 104
Enter First name : Preston
Enter Last name : paul
Enter major : B.Tech
Enter GPA : 8.4
Enter 5 student details :
Enter ID number   : 105
Enter First name : Steve
Enter Last name : jobs
Enter major : B.Sc
Enter GPA : 5.6
Enter a user name : Duke
Duke - student details found ...
===============================================
Student Id Number : 102
First name        : Duke
Last name         : james
Major             : B.Com
GPA               : 2.0
lenovo@lenovo-Vbox:~$

lenovo@lenovo-Vbox:~$ ./a.out
Enter 1 student details :
Enter ID number   : 101
Enter First name : Mars
Enter Last name : Martin
Enter major : B.Tech
Enter GPA : 4.3
Enter 2 student details :
Enter ID number   : 102
Enter First name : Duke
Enter Last name : james
Enter major : B.Com
Enter GPA : 2.0
Enter 3 student details :
Enter ID number   : 103
Enter First name : Belew
Enter Last name : kem
Enter major : B.Sc
Enter GPA : 3.3
Enter 4 student details :
Enter ID number   : 104
Enter First name : Preston
Enter Last name : paul
Enter major : B.Tech
Enter GPA : 8.4
Enter 5 student details :
Enter ID number   : 105
Enter First name : Steve
Enter Last name : jobs
Enter major : B.Sc
Enter GPA : 5.6
Enter a user name : kems
kems - - student information not found
lenovo@lenovo-Vbox:~$


*/

Add a comment
Know the answer?
Add Answer to:
You are asked to define a user-defined data type for students, that will contain the following...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • For C++ program Your program should first prompt the user for the number of students they...

    For C++ program Your program should first prompt the user for the number of students they wish to enter. For each student, the user will be prompted to enter the student’s name, how many tests the student has taken, and the grade for each test. Each test’s grade will be inputted as a number representing the grade for that test. Once each student’s information has been entered, the program will display the number of students. Additionally, each student will have...

  • Python: Printing Student Data Ask the user: "How many students are in the class?" Read in...

    Python: Printing Student Data Ask the user: "How many students are in the class?" Read in the number of students If there are students For each student Ask for the name of the student: "Enter the name of student:" Read in the name of the student If the student's name is greater than 24 characters Do not display this student's data Do not ask for their gpa Print: "Name of student cannot exceed 24 characters." Ask for the gpa of...

  • In C++ Write a menu driven C++ program to read a file containing information for a list of Students, process the data, t...

    In C++ Write a menu driven C++ program to read a file containing information for a list of Students, process the data, then present a menu to the user, and at the end print a final report shown below. You may(should) use the structures you developed for the previous assignment to make it easier to complete this assignment, but it is not required. Required Menu Operations are: Read Students’ data from a file to update the list (refer to sample...

  • Write a program that performs the following: 1. Presents the user a menu where they choose...

    Write a program that performs the following: 1. Presents the user a menu where they choose between:              a. Add a new student to the class                           i. Prompts for first name, last name                           ii. If assignments already exist, ask user for new student’s scores to assignments              b. Assign grades for a new assignment                           i. If students already exist, prompt user with student name, ask them for score                           ii. Students created after assignment will need to...

  • You are to write a program which will ask the user for number of students (dynamic...

    You are to write a program which will ask the user for number of students (dynamic array of class Student). For each student, you will ask for first name and number of grades (dynamic array of grades as a variable in Student). **The program should give the student random grades from 0-100** Find the averages of each student and display the information. **Display name, grades, and average neatly in a function in the Student class called Display()** Sort the students...

  • You are to write a program which will ask the user for number of students (dynamic...

    You are to write a program which will ask the user for number of students (dynamic array of class Student). For each student, you will ask for first name and number of grades (dynamic array of grades as a variable in Student). **The program should give the student random grades from 0-100** Find the averages of each student and display the information. **Display name, grades, and average neatly in a function in the Student class called Display()** Sort the students...

  • This code should be written in php. Write a program that allows the user to input...

    This code should be written in php. Write a program that allows the user to input a student's last name, along with that student's grades in English, History, Math, Science, and Geography. When the user submits this information, store it in an associative array, like this: Smith=61 67 75 80 72 where the key is the student's last name, and the grades are combined into a single space-delimited string. Return the user back to the data entry screen, to allow...

  • A. Consider “inclass2.h” header file. Define a structure which can hold the following student information: id,...

    A. Consider “inclass2.h” header file. Define a structure which can hold the following student information: id, first name, last name, and gpa. Use appropriate header file guards. ( Max size of first and last name is 20, id is 7 and gpa is double). B. Consider an array of student struct with the MAX_SIZE 10 and a first name. These will be provided as an input to your function. Write a function/method that using the given inputs prints out the...

  • You are asked to build and test the following system using Java and the object-oriented concepts ...

    You are asked to build and test the following system using Java and the object-oriented concepts you learned in this course: Project (20 marks) CIT College of Information technology has students, faculty, courses and departments. You are asked to create a program to manage all these information's. Create a class CIT to represents the following: Array of Students, each student is represented by class Student. Array of Faculty, each faculty is represented by class Faculty. Array of Course, each course...

  • IN C PLEASE Question 16 A. Consider “inclass2.h” header file. Define a structure which can hold...

    IN C PLEASE Question 16 A. Consider “inclass2.h” header file. Define a structure which can hold the following student information: id, first name, last name, and gpa. Use appropriate header file guards. ( Max size of first and last name is 20, id is 7 and gpa is double). B. Consider an array of student struct with the MAX_SIZE 10 and a first name. These will be provided as an input to your function. Write a function/method that using the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT