Question


Consider the Tollowing class declaration: class student record public: int age; string name; double gpa; }: Implement a void
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code

#include<iostream>
#include<string>
#include<fstream>
using namespace std;

class student_record
{
public:
   int age;
   string name;
   double gpa;
};

void readRecords(student_record *S_db,int capacity,int *count)
{
  
   ifstream inFIle;
   int i=0;
   inFIle.open("university_body.txt");
   if(!inFIle)
   {
       cout<<"Error in opening file.File not found."<<endl;
       return;
   }
   while(inFIle>>S_db[i].name>>S_db[i].age>>S_db[i].gpa)
   {
       if(i==capacity)
       {
           cout<<"Array is full. No room for new reords";
           return;
       }
       i++;
       *count=i;
   }
}

int main()
{
   student_record *S_db;
   const int CAPACITY=25;
   int count=0;
   S_db=new student_record[CAPACITY];
   readRecords(S_db,CAPACITY,&count);
   cout<<"Records read from the file: "<<endl;
   cout<<"--------------------------------------------"<<endl;
   for(int i=0;i<count;i++)
   {
       cout<<"Name: "<<S_db[i].name<<endl<<"Age: "<<S_db[i].age<<endl<<"GPA: "<<S_db[i].name<<endl<<endl;
   }
}

university_body.txt file for proof

output

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
Consider the Tollowing class declaration: class student record public: int age; string name; double gpa; }:...
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
  • C++ assignment help! The instructions are below, i included the main driver, i just need help...

    C++ assignment help! The instructions are below, i included the main driver, i just need help with calling the functions in the main function This assignment will access your skills using C++ strings and dynamic arrays. After completing this assignment you will be able to do the following: (1) allocate memory dynamically, (2) implement a default constructor, (3) insert and remove an item from an unsorted dynamic array of strings, (4) use the string class member functions, (5) implement a...

  • please write in c++. 4 Derived class JPG 4.1 Class declaration • The class JPG inherits...

    please write in c++. 4 Derived class JPG 4.1 Class declaration • The class JPG inherits from File and is a non-abstract class. 1. Hence objects of the class JPG can be instantiated. 2. To do so, we must override the pure virtual function clone() in the base class. • The class declaration is given below. class JPG : public File { public: JPG(const std::string& n, int n, int w, const double rgb()) : File(...) { // ... } *JPG()...

  • Data Structures and Algorithm Analysis – Cop 3530 Module 3 – Programming Assignment This assignment will...

    Data Structures and Algorithm Analysis – Cop 3530 Module 3 – Programming Assignment This assignment will access your skills using C++ strings and dynamic arrays. After completing this assignment you will be able to do the following: (1) allocate memory dynamically, (2) implement a default constructor, (3) insert and remove an item from an unsorted dynamic array of strings, (4) use the string class member functions, (5) implement a copy constructor, (6) overload the assignment operator, (7) overload the insertion...

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

  • please write the code in C++ 2 Base class File 3 Derived class PDF 3.1 Class...

    please write the code in C++ 2 Base class File 3 Derived class PDF 3.1 Class declaration • The class PDF inherits from File and is a non-abstract class 1. Hence objects of the class PDF can be instantiated. 2. To do so, we must override the pure virtual function clone) in the base class • The class declaration is given below. • The complete class declaration is given below, copy and paste it into your file. . It is...

  • 2 Class Vec Message1 2.1 Introduction • Write a class Vec Message1 with the following declaration....

    2 Class Vec Message1 2.1 Introduction • Write a class Vec Message1 with the following declaration. class Vec_Message1 { public: Vec_Message1(); Vec_Message1(int n); Vec_Message1(int n, const Message1 &a); Vec_Message1(const Vec_Message1 &orig); Vec_Message1& operator= (const Vec_Message1 &rhs); ~Vec_Message1(); int capacity() const; int size() const; Message1 front() const; Message1 back() const; void clear(); void pop_back(); void push_back(const Message1 &a); Message1& at(int n); private: void allocate(); void release(); int _capacity; int _size; Message1 * _vec; }; 2.2 allocate() and release() • Examine the...

  • 1. Here are codes to define a stack class based on dynamic array, please complete the...

    1. Here are codes to define a stack class based on dynamic array, please complete the copy constructor //--- Definition of Stack copy constructor Stack::Stack(const Stack & original) : myCapacity(original.myCapacity), myTop(original.myTop) { //--- Get new array for copy myArray = new(nothrow) StackElement[myCapacity]; if (myArray != 0) // check if memory available                         // copy original's array member into this new array {              // Please complete the function here        } else {          cerr << "*Inadequate memory to allocate...

  • CSCI 135 Test 2 Name: 6, (21%) Consider the following definitions: class Student class Section public:...

    CSCI 135 Test 2 Name: 6, (21%) Consider the following definitions: class Student class Section public: string getFirst ) string getLast () int getGrade) void set First (string s) void setLast (string ) void setGrade (nt g): numStudents () Student getNthStudent (int n) string getCourse ) string getInstructor ); private: private: string firstName string lastName Student students [SIZE: string course; string structor; grade; Write a function, honorRoll that returns a dynamic array containing only those students in section sec with...

  • Instructions: Consider the following C++ program. At the top you can see the interface for the...

    Instructions: Consider the following C++ program. At the top you can see the interface for the Student class. Below this is the implementation of the Student class methods. Finally, we have a very small main program. #include <string> #include <fstream> #include <iostream> using namespace std; class Student { public: Student(); Student(const Student & student); ~Student(); void Set(const int uaid, const string name, const float gpa); void Get(int & uaid, string & name, float & gpa) const; void Print() const; void...

  • Use C++! This program uses the class myStack to determine the highest GPA from a list of students with their GPA.The program also outputs the names of the students who received the highest GPA. Redo t...

    Use C++! This program uses the class myStack to determine the highest GPA from a list of students with their GPA.The program also outputs the names of the students who received the highest GPA. Redo this program so that it uses the STL list and STL queue! Thank you! HighestGPAData.txt* 3.4 Randy 3.2 Kathy 2.5 Colt 3.4 Tom 3.8 Ron 3.8 Mickey 3.6 Peter 3.5 Donald 3.8 Cindy 3.7 Dome 3.9 Andy 3.8 Fox 3.9 Minnie 2.7 Gilda 3.9 Vinay...

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