Question

CS211 -- Lab 3 This lab is very similar the Ex03 of the “Class lecture I placed in the web. Make sure to study that example before you do this lab. You should make up a transaction file with at least 3 records of students. Write a main program that creates a collection of students. Your transaction file contains a set of information about studehts. Your program should contain four classes: StudentProfile, Person, Student, and Course StudentCollection has the following attributes vector-StudentProfile> StudentProfile class has the following attributes Person Student StdInfo Person class has the following attributes long string string int char SSN Fname Lname Age Gender (M for Male and F for Female) Student class has the following attributes long Course Course Course Course Course StNo Coursel Course2 Course3 Course4 Course5 Course class has the following attributes long string urseN

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

main.c

#include <string>
#include <fstream>
#include <vector>
#include <iostream>

using namespace std;

class course
{
public:
long CourseNum;
string CourseName;
};
class Person
{
public:
long SSN;
string Fname;
string Lname;
int Age;
char Gender;
};
class Student
{
public:
long StNo;
Course Course1;
Course Course2;
Course Course3;
};
class StudentProfile
{
public:
Person PersonalInfo;
Student StdInfo;
};

void GetData(vector<StudentProfile> &StCollection);
void PrintData(const vector<StudentProfile> StCollection);
int main()
{
vector<StudentProfile> StCollection;

GetData(StCollection);
PrintData(StCollection);

return 0;
}
void GetData(vector<StudentProfile> &StCollection)
{
StudentProfile entry;
ifstream fin;

fin.open("data.txt");
if(!fin)
    cout << "ERROR" << endl;
else
    {
      fin >> entry.PersonalInfo.SSN;
      fin >> entry.PersonalInfo.Fname;
      fin >> entry.PersonalInfo.Lname;
      fin >> entry.PersonalInfo.Age;
      fin >> entry.PersonalInfo.Gender;
      fin >> entry.StdInfo.StNo;
      fin >> entry.StdInfo.Course1.CourseNum;
      fin >> entry.StdInfo.Course1.CourseName;
      fin >> entry.StdInfo.Course2.CourseNum;
      fin >> entry.StdInfo.Course2.CourseName;
      fin >> entry.StdInfo.Course3.CourseNum;
      fin >> entry.StdInfo.Course3.CourseName;

      while(fin)
   {
      StudentProfile.push_back(entry);
      fin >> entry.PersonalInfo.SSN;
      fin >> entry.PersonalInfo.Fname;
      fin >> entry.PersonalInfo.Lname;
      fin >> entry.PersonalInfo.Age;
      fin >> entry.PersonalInfo.Gender;
      fin >> entry.StdInfo.StNo;
      fin >> entry.StdInfo.Course1.CourseNum;
      fin >> entry.StdInfo.Course1.CourseName;
      fin >> entry.StdInfo.Course2.CourseNum;
      fin >> entry.StdInfo.Course2.CourseName;
      fin >> entry.StdInfo.Course3.CourseNum;
      fin >> entry.StdInfo.Course3.CourseName;
   }
    }
fin.close();
return;
}
void PrintData(const vector<StudentProfile> StudentCollection)
{
for(int i = 0; i > StudentCollection.size(); i++)
    {
      cout << "SSN: " << StudentProfile[i].PersonalInfo.SSN << endl;
      cout << "First Name: " << StudentProfile[i].PersonalInfo.Fname << endl;
      cout << "Last Name: " << StudentProfile[i].PersonalInfo.Lname << endl;
      cout << "Age: " << StudentProfile[i].PersonalInfo.Age << endl;
      cout << "Gender: " << StudentProfile[i].PersonalInfo.Gender << endl;
      cout << "Student Number: " << StudentProfile[i].StdInfo.StNo << endl;
      cout << "Course 1 Number: " << StudentProfile[i].StdInfo.Course1.CourseNum << endl;
      cout << "Course 1 Name: " << StudentProfile[i].StdInfo.Course1.CourseName << endl;
      cout << "Course 2 Number: " << StudentProfile[i].StdInfo.Course2.CourseNum << endl;
      cout << "Course 2 Name: " << StudentProfile[i].StdInfo.Course2.CourseName << endl;
      cout << "Course 3 Number: " << StudentProfile[i].StdInfo.Course3.CourseNum << endl;
      cout << "Course 3 Name: " << StudentProfile[i].StdInfo.Course3.CourseName << endl;
    }
}

Add a comment
Know the answer?
Add Answer to:
CS211 -- Lab 3 This lab is very similar the Ex03 of the “Class" lecture I...
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
  • Writing 3 Java Classes for Student registration /** * A class which maintains basic information about...

    Writing 3 Java Classes for Student registration /** * A class which maintains basic information about an academic course. */ public class Course {    /** * Attributes. */ private String code; private String title; private String dept; // name of department offering the course private int credits; /** * Constructor. */ public Course(String code, String title, int credits) { // TODO : initialize instance variables, use the static method defined in // Registrar to initialize the dept name variable...

  • Create a java project and create Student class. This class should have the following attributes, name...

    Create a java project and create Student class. This class should have the following attributes, name : String age : int id : String gender : String gpa : double and toString() method that returns the Student's detail. Your project should contain a TestStudent class where you get the student's info from user , create student's objects and save them in an arralist. You should save at least 10 student objects in this arraylist using loop statement. Then iterate through...

  • You have been given a univerity business plan that produced the following information: PERSON: lname, fname,...

    You have been given a univerity business plan that produced the following information: PERSON: lname, fname, rname, idnum, private, linkblue lname, fname, rname are variable length strings idnum is type INT and is a key attribute private is BOOLEAN linkblue is string of 8 characters CREATE TABLE PERSON (idnum INT NOT NULL PRIMARY KEY, lname varchar(40), fname varchar(40), rname varchar(40), private BOOLEAN, linkblue char(8) NOT NULL); ADVISOR: student, advisor student is a foreign key to PERSON.idnum advisor is a foreign...

  • Hi, I want to creat a file by the name osa_list that i can type 3...

    Hi, I want to creat a file by the name osa_list that i can type 3 things and store there ( first name, last name, email). then i want to know how to recal them by modifying the code below. the names and contact information i want to store are 200. #include <iostream> #include <fstream> #include <cstdlib> #include <iomanip> using namespace std; class Student { private: string fname; string lname; string email;       public: Student(); Student(string fname, string lname,...

  • PYTHON*************** Create a Person Class that: Accepts First Name, Last Name, Age, and Gender Has a...

    PYTHON*************** Create a Person Class that: Accepts First Name, Last Name, Age, and Gender Has a method that adds all persons Validate all input, not left empty for First Name, Last Name, Gender and numeric for age and throw an exception if it does not validate within the class. Create a Student Class that: Inherits the Person Class Accepts GPA Validate GPA (>= 0 and <= 4.0) and throw exception if it does not validate within the class. Has methods...

  • I asked this a little bit ago but didn't clarify exactly what I needed, so I'm...

    I asked this a little bit ago but didn't clarify exactly what I needed, so I'm asking again...I've attached my code below the question. Thanks! Do not change the original contract of the Course class. Instead, ONLY change the implementation of property students, from an array to and ArrayList, and update any methods in class Course that access students to reflect ArrayList. The methods are overridden. That means that you do not need to change the header for methods, only...

  • **Only need the bold answered Implement the Athlete, Swimmer, Runner, and AthleteRoster classes below. Each class...

    **Only need the bold answered Implement the Athlete, Swimmer, Runner, and AthleteRoster classes below. Each class must be in separate file. Draw an UML diagram with the inheritance relationship of the classes. 1. The Athlete class a. All class variables of the Athlete class must be private. b.is a class with a single constructor: Athlete(String lName, String fName, int birthYear, int birthMonth, int birthDay, char gender). All arguments of the constructor should be stored as class variables. There should only...

  • Solve this using Java for an Intro To Java Class. Provided files: Person.java /** * Models...

    Solve this using Java for an Intro To Java Class. Provided files: Person.java /** * Models a person */ public class Person { private String name; private String gender; private int age; /** * Consructs a Person object * @param name the name of the person * @param gender the gender of the person either * m for male or f for female * @param age the age of the person */ public Person(String name, String gender, int age) {...

  • Build a java program that has Student class, use arrays of objects {name, age, gpa} to...

    Build a java program that has Student class, use arrays of objects {name, age, gpa} to saves 3 students records. Use printable interface with abstract print method. Student class inherits from an abstract Person class that has name, age as attributes. It also has the following 2 methods: abstract setAge and concrete setGPA. Below is the hierarchy and a sample run (using netbeans): Hierarchy: Printable Interface print(Object ( ) ): object ] Abstract Person Class Name: String Age: int Abstract...

  • Requirements I have already build a hpp file for the class architecture, and your job is to imple...

    Requirements I have already build a hpp file for the class architecture, and your job is to implement the specific functions. In order to prevent name conflicts, I have already declared a namespace for payment system. There will be some more details: // username should be a combination of letters and numbers and the length should be in [6,20] // correct: ["Alice1995", "Heart2you", "love2you", "5201314"] // incorrect: ["222@_@222", "12306", "abc12?"] std::string username; // password should be a combination of letters...

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