Question

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 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

Code:

#include<stdio.h>
// structure student to hold student data
struct student{
char *id;
char *firstname;
char *lastname;
double gpa;
};

// method to print all ids having same first name
void same_first_name(char *name ,struct student arr[10]){
for(int i=0;i<5;i++){
if(arr[i].firstname == name){
  
printf("%s",arr[i].id);
printf("\n");
}
}
  
}
int main(){
  
struct student arr[10];
  
// initializing the data
arr[0].id="aaa111";
arr[0].firstname="Mary";
arr[0].lastname="Robin";
arr[0].gpa=4.0;
arr[1].id="bbb222";
arr[1].firstname="Ada";
arr[1].lastname="Thorne";
arr[1].gpa=3.9;
arr[2].id="ccc333";
arr[2].firstname="Mary";
arr[2].lastname="Grey";
arr[2].gpa=3.8;
arr[3].id="ddd444";
arr[3].firstname="Arthur";
arr[3].lastname="Eden";
arr[3].gpa=3.7;
arr[4].id="eee555";
arr[4].firstname="Mary";
arr[4].lastname="Aslani";
arr[4].gpa=3.6;
  
// variable to hold the name
char *name="Mary";
  
// calling the method to print ids with same firstname as our variable
same_first_name(name ,arr);
return 0;
  
}

#include<stdio.h> // structure student to hold student data struct student{ char *id; char *firstname; char *lastname; doublearr[1].firstname=Ada; arr[1].lastname=Thorne; arr[1].gpa=3.9; arr[2].id=ccc333; arr[2].firstname=Mary; arr[2]. lastna

Output:

aaa111 CCC333 eee555

Add a comment
Know the answer?
Add Answer to:
IN C PLEASE Question 16 A. Consider “inclass2.h” header file. Define a structure which can hold...
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
  • 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...

  • 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...

  • 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,...

  • 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...

  • c++ The program will be recieved from the user as input name of an input file...

    c++ The program will be recieved from the user as input name of an input file and and output.file. then read in a list of name, id# and score from input file (inputFile.txt) and initilized the array of struct. find the student with the higher score and output the students info in the output file obtain the sum of all score and output the resurl in output file. prompt the user for a name to search for, when it find...

  • 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()...

  • In header file (.h) and c++ file format (.cpp). A local company has asked you to...

    In header file (.h) and c++ file format (.cpp). A local company has asked you to write a program which creates an Employee class, a vector of Employee class objects, and fills the objects with employee data, creating a "database" of employee information. The program allows the user to repeatedly search for an employee in the vector by entering the employee's ID number and if found, display the employee's data. The Employee_C class should have the following data and in...

  • C++ Programming

    PROGRAM DESCRIPTIONIn this project, you have to write a C++ program to keep track of grades of students using structures and files.You are provided a data file named student.dat. Open the file to view it. Keep a backup of this file all the time since you will be editing this file in the program and may lose the content.The file has multiple rows—each row represents a student. The data items are in order: last name, first name including any middle...

  • Kindly solve this using C PROGRAMMING ONLY. 4. Write a program marks.c which consists of a...

    Kindly solve this using C PROGRAMMING ONLY. 4. Write a program marks.c which consists of a main function and three other functions called. readmarks , changemarks (, and writemarks() The program begins by calling the function readmarks () to read the input file marksin. txt which consists of a series of lines containing a student ID number (an integer) and a numeric mark (a float). Once the ID numbers and marks have been read into arrays (by readmarks () the...

  • In Java(using BlueJ) Purpose Purpose is to practice using file input and output, and array list...

    In Java(using BlueJ) Purpose Purpose is to practice using file input and output, and array list of objects. Also, this lab specification tells you only what to do, you now have more responsibility to design how to do it. Problem description You are given a text file called 'Students.txt' that contains information on many students. Your program reads the file, creating many Student objects, all of which will be stored into an array list of Student objects, in the Students...

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