Question

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 ID for all the students with the same first name.

INPUTS: The struct array should be declared and initialized in the main function. The following students information should be used to initialize the first 5 elements of the array Mary Robin aaa111 4.0

Ada Thorne bbb222 3.9

Mary Gray ccc333 3.8

Arthur Eden ddd444 3.7

Mary Aslani eee555 3.6

A variable should be declared and initialized with the name “Mary” in the main and should be provided to the function in part B of the question as one of the inputs ( to print out the id of the students with the same first name).

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

// studentsdata.txt

Mary Robin aaa111 4.0
Ada Thorne bbb222 3.9
Mary Gray ccc333 3.8
Arthur Eden ddd444 3.7
Mary Aslani eee555 3.6

______________________

// inclass2.h

struct Student{
char firstName[20];
char lastName[20];
char id[7];
double gpa;
};
  

________________________

// inclass2.c

#include <string.h>
#include <stdio.h>
#include "inclass2.h"


void searchStudentsFirstName(struct Student arr[],int cnt,char fname[])
{
int flag=0,i;
for(i=0;i<cnt;i++)
{
if(strcmp(arr[i].firstName,fname)==0)
{
printf("%s\n",arr[i].id);
flag=1;
}
}
if(flag==0)
{
printf("No students found\n");
}
}

_____________________________

// main.c

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "inclass2.h"
int main()
{
char fname[20],lname[20],id[7];
double gpa;
const int MAX_SIZE=10;
int cnt=0;
struct Student stds[MAX_SIZE];
FILE* f1;
f1 = fopen("studentdata.txt", "r");

//Opening the output file in read mode
  
if (f1 == NULL) {
printf("** File not found **");
exit(1);
}
else {

//Reading the data from the file
while(fscanf(f1,"%s%s%s%lf",fname,lname,id,&gpa)!=EOF)
{
strcpy(stds[cnt].firstName,fname);
strcpy(stds[cnt].lastName,lname);
strcpy(stds[cnt].id,id);
stds[cnt].gpa=gpa;
cnt++;
  
}
//closing the files
fclose(f1);

  
char first[20]={"Mary"};
searchStudentsFirstName(stds,cnt,first);
}


  
return 0;
}

__________________________

Output:


_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
A. Consider “inclass2.h” header file. Define a structure which can hold the following student information: id,...
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
  • 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...

  • Write a C++ program that includes the following: Define the class Student in the header file Stu...

    Write a C++ program that includes the following: Define the class Student in the header file Student.h. #ifndef STUDENT_H #define STUDENT_H #include <string> #include <iostream> using namespace std; class Student { public: // Default constructor Student() { } // Creates a student with the specified id and name. Student(int id, const string& name) { } // Returns the student name. string get_name() const { } // Returns the student id. int get_id () const { } // Sets the student...

  • Define a class called Student with ID (string), name (string), units (int) and gpa (double). Define...

    Define a class called Student with ID (string), name (string), units (int) and gpa (double). Define a constructor with default values to initialize strings to NULL, unit to 0 and gpa to 0.0. Define a copy constructor to initialize class members to those of another Student passed to it as parameters. Overload the assignment operator (=) to assign one Student to another. Define a member function called read() for reading Student data from the user and a function called print()...

  • Files given in this assignment (right-click on the file to download) Assignment7.cpp (need to complete) Student.h...

    Files given in this assignment (right-click on the file to download) Assignment7.cpp (need to complete) Student.h (Given. Just use it, don't change it!) Student.cpp (Partially filled, need to complete) 1. Assignment description In this assignment, you will write a simple class roster management system for ASU CSE100. Step #1: First, you will need to finish the design of class Student. See the following UML diagram for Student class, the relevant header file (class declaration) is given to you as Student.h,...

  • O Fit to page ID Page vi Programming assignment 6 Assume that the following student information...

    O Fit to page ID Page vi Programming assignment 6 Assume that the following student information is stored in a MATLAB structure student student name contains the full name of the student student..pa contains the GPA of the student student.standing contains whether the student is in good academic standing (true/fake) Write a function update(student, field, value) that does the following: Thes as an input a student structure, a student field name, and a value Epla 2. Returns a student structure...

  • 1. Create a file that contains 3 rows of data of the form: First Name Middle...

    1. Create a file that contains 3 rows of data of the form: First Name Middle Name Last Name Month Day Year Month Day Year GPA. This file represents student data consisting of first name, middle name, last name, registration month, registration day, registration year, birth month, birth day, birth year, current gpa. ...or you may download the data file inPut.txt. inPut.txt reads:​​​​​​​ Tsia Brian Smith 9 1 2013 2 27 1994 4.0 Harper Willis Smith 9 2 2013 9...

  • I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student...

    I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student {    private String name;    private double gpa;    private int idNumber;    public Student() {        this.name = "";        this.gpa = 0;        this.idNumber = 0;    }    public Student(String name, double gpa, int idNumber) {        this.name = name;        this.gpa = gpa;        this.idNumber = idNumber;    }    public Student(Student s)...

  • Write a java code : Student ID at University is composed of year of admission and...

    Write a java code : Student ID at University is composed of year of admission and students number. we aim to implement a structure that improves operations of inserting and searching for a student. To enhance these operations, we will build a tree of linked lists (TreeOfLists) to combine advantages of both structures. Each node in this tree contains a linked list of all students who were admitted in that year. Each node in the linked list represents a student(id,...

  • Problem Specification: Write a C++ program to calculate student’s GPA for the semester in your class. For each student, the program should accept a student’s name, ID number and the number of courses...

    Problem Specification:Write a C++ program to calculate student’s GPA for the semester in your class. For each student,the program should accept a student’s name, ID number and the number of courses he/she istaking, then for each course the following data is needed the course number a string e.g. BU 101 course credits “an integer” grade received for the course “a character”.The program should display each student’s information and their courses information. It shouldalso display the GPA for the semester. The...

  • Code in C language ADT: typedef struct{ int ID; float salary; int age; }Employee; ...

    code in C language ADT: typedef struct{ int ID; float salary; int age; }Employee; Specification: In this lab, five functions need to be implemented using the given ADT. 1. Employee* readRecord(FILE*) This function receives a FILE pointer created before. It reads a line from the provided csv file, and creates an Employee struct pointer with the information from that line then returns the pointer back to the calling function. Each line in the provided csv file contains the id, salary,...

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
ADVERTISEMENT