(Solved Homework): Redo the code below to make the data persistent. You will have to save information in a file or files so that the application will pick up previously stored dat…

C++ Data Persistance Help

Redo the code below to make the data persistent. You will have to save information in a file or files so that the application will pick up previously stored data and still operate as intended in Lab1 to

Don't use plagiarized sources. Get Your Custom Essay on
(Solved Homework): Redo the code below to make the data persistent. You will have to save information in a file or files so that the application will pick up previously stored dat…
Get an essay WRITTEN FOR YOU, Plagiarism free, and by an EXPERT!
Order Essay

Write a program that allows the user to initially enter information on 4 students and 10 courses. Have the program associate each student to at least four courses for a semester session. The program will display a report showing the assigned courses for each students with the total number of credits.

The student information should include:

1. student ID

2. first name

3. last name

The course information should include:

1. Course ID

2. Course name

3. Number of credits

Design requirement:

A student will be assigned a course through a session. The session should include the following attributes:

1. session ID

2. student ID

3. course ID

4. start date

5. end date

.

See Code Below:

course.h

#include<iostream>
using namespace std;

struct course
{
string CourseName;
string CourseID;
int numberOfCredits;
};

student.h

#include<iostream>
using namespace std;

struct student
{
string fname;
string lname;
string stuID;
};

session.h

#include<iostream>
using namespace std;

struct session
{
int sessionID;
string stuID;
string courseID;
string startDate;
string endDate;
int totalCredits;
};

main.cpp

#include<iostream>
using namespace std;
#include “student.h”
#include “course.h”
#include “session.h”

void fillStudents(student arg[], int size)
{
for (int i = 0; i < size; i++)
{
cout <<“Student #”<<i+1<<endl;
cout <<“==========”<<endl;
cout <<“Enter a student ID (i.e 97626): “;
cin >>arg[i].stuID;
cout <<“Enter the first name (i.e Ryan): “;
cin >>arg[i].fname;
cout <<“Enter the last name (i.e Brown): “;
cin >>arg[i].lname;
system(“CLS”);
}
}

void fillCourses(course c[], int size)
{
for (int i = 0; i < size; i++)
{
cout <<“Course #”<<i+1<<endl;
cout <<“==========”<<endl;
cout <<“Enter course name (i.e Data-Structures (put – instead of spaces)): “;
cin >>c[i].CourseName;
cout <<“Enter course ID (i.e CS-230 (put – instead of spaces)): “;
cin >>c[i].CourseID;
cout <<“Enter number of credits (i.e 3): “;
cin >>c[i].numberOfCredits;
system(“CLS”);
}
}

string CourseN(int choice, course ch[])
{
switch(choice)
{
case 1:
return ch[0].CourseID+” “+ch[0].CourseName;
break;
case 2:
return ch[1].CourseID+” “+ch[1].CourseName;
break;
case 3:
return ch[2].CourseID+” “+ch[2].CourseName;
break;
case 4:
return ch[3].CourseID+” “+ch[3].CourseName;
break;
case 5:
return ch[4].CourseID+” “+ch[4].CourseName;
break;
case 6:
return ch[5].CourseID+” “+ch[5].CourseName;
break;
case 7:
return ch[6].CourseID+” “+ch[6].CourseName;
break;
case 8:
return ch[7].CourseID+” “+ch[7].CourseName;
break;
case 9:
return ch[8].CourseID+” “+ch[8].CourseName;
break;
case 10:
return ch[9].CourseID+” “+ch[9].CourseName;
break;
default:
cout<<“Invalid decison!! Good Bye!”<<endl;
exit(0);
}
}

int creditTotal(int sel, course ch[])
{
switch(sel)
{
case 1:
return ch[0].numberOfCredits;
break;
case 2:
return ch[1].numberOfCredits;
break;
case 3:
return ch[2].numberOfCredits;
break;
case 4:
return ch[3].numberOfCredits;
break;
case 5:
return ch[4].numberOfCredits;
break;
case 6:
return ch[5].numberOfCredits;
break;
case 7:
return ch[6].numberOfCredits;
break;
case 8:
return ch[7].numberOfCredits;
break;
case 9:
return ch[8].numberOfCredits;
break;
case 10:
return ch[9].numberOfCredits;
break;
default:
cout<<“Invalid Decision!! Good Bye!”<<endl;
exit(0);
}
}

void fillSession(student arg[], course c[], session s[])
{
int c1, c2, c3, c4;
string ch1, ch2, ch3, ch4;
string startDate, endDate;
int cr1, cr2, cr3, cr4;

for (int i = 0; i < 4; i++)
{
for(int j = 0; j < 10; j++)
{
cout<<“class #”<<j+1<<” tt”<<c[j].CourseID<<” tt”<<c[j].CourseName<<” ttt”<<“Credits: “<<c[j].numberOfCredits<<“nn”;
}

cout<<“Enter your 1st class choice: “;
cin>>c1;
ch1=CourseN(c1,c);
cout<<“Enter your 2nd class choice: “;
cin>>c2;
ch2=CourseN(c2,c);
cout<<“Enter your 3rd class choice: “;
cin>>c3;
ch3=CourseN(c3,c);
cout<<“Enter your 4th class choice: “;
cin>>c4;
ch4=CourseN(c4,c);

s[i].courseID=ch1+”n”+ch2+”n”+ch3+”n”+ch4;
cout<<“Enter a start date for your classes (i.e mm/dd/yyyy): “;
cin>>startDate;
s[i].startDate=startDate;
cout<<“Enter a end date for your classes (i.e mm/dd/yyyy): “;
cin>>endDate;
s[i].endDate=endDate;

cr1=creditTotal(c1, c);
cr2=creditTotal(c2, c);
cr3=creditTotal(c3, c);
cr4=creditTotal(c4, c);

s[i].totalCredits=cr1+cr2+cr3+cr4;

c1=0;
c2=0;
c3=0;
c4=0;

system(“CLS”);
}
}

void display_report(student s[], course c[], session se[])
{
for (int i = 0; i < 4; i++)
{
cout<<“Student ID: “<<s[i].stuID<<“n”<<endl;
cout<<“Student Name: “<<s[i].lname<<“, “<<s[i].fname<<“n”<<endl;
cout<<“Course IDs: n”<<se[i].courseID<<“n”<<endl;
cout<<“Start Date: n”<<se[i].startDate<<“n”<<endl;
cout<<“End Date: n”<<se[i].endDate<<“n”<<endl;
cout<<“Total Credits: “<<se[i].totalCredits<<“n”<<endl;
cout<<“n”<<endl;
}
}

int main()
{
cout<<“Welcome to the CS 230 Data Structures class add program!”<<endl;
cout<<“Please follow the prompt to gain a report of your courses for the year: “<<endl<<endl;
//declare and initialize 4 students
student stu[4];
fillStudents(stu, 4);

//declare and initialize 10 courses
course courses[10];
fillCourses(courses, 10);

//assign 4 courses for each student
cout<<“Enter a class selection based on the chart above (1-10), please do not choose the same class twice: “<<endl;
cout<<“Each student goes by how their information was added”<<endl<<endl;

session sessions[4];
fillSession(stu, courses, sessions);

//display a report showing each student with his/her courses
//show the total number of credits for each student
cout<<“Please find your name and other important information below to see your classes and credit totals: nn”<<endl;
cout <<“==========”<<endl;
display_report(stu, courses, sessions);
cout <<“==========”<<endl;

system(“PAUSE”);
return 0;
}

Expert Answer

 

//============================================================================
// Name        : main.cpp
// Author      : Ramachandra jr
// Version     :
// Copyright   : GNU GPL Licesnse
// Description : Hello World in C++, Ansi-style
//============================================================================

#include<iostream>
#include<fstream>
#include <cstdlib>
#include “student.h”
#include “course.h”
#include “session.h”
using namespace std;

void fillStudents(student arg[], int size)
{
for (int i = 0; i < size; i++)
{
cout <<“Student #”<<i+1<<endl;
cout <<“==========”<<endl;
cout <<“Enter a student ID (i.e 97626): “;
cin >>arg[i].stuID;
cout <<“Enter the first name (i.e Ryan): “;
cin >>arg[i].fname;
cout <<“Enter the last name (i.e Brown): “;
cin >>arg[i].lname;
system(“clear”);
}
}

void fillCourses(course c[], int size)
{
for (int i = 0; i < size; i++)
{
cout <<“Course #”<<i+1<<endl;
cout <<“==========”<<endl;
cout <<“Enter course name (i.e Data-Structures (put – instead of spaces)): “;
cin >>c[i].CourseName;
cout <<“Enter course ID (i.e CS-230 (put – instead of spaces)): “;
cin >>c[i].CourseID;
cout <<“Enter number of credits (i.e 3): “;
cin >>c[i].numberOfCredits;
system(“clear”);
}
}

string CourseN(int choice, course ch[])
{
switch(choice)
{
case 1:
return ch[0].CourseID+” “+ch[0].CourseName;
break;
case 2:
return ch[1].CourseID+” “+ch[1].CourseName;
break;
case 3:
return ch[2].CourseID+” “+ch[2].CourseName;
break;
case 4:
return ch[3].CourseID+” “+ch[3].CourseName;
break;
case 5:
return ch[4].CourseID+” “+ch[4].CourseName;
break;
case 6:
return ch[5].CourseID+” “+ch[5].CourseName;
break;
case 7:
return ch[6].CourseID+” “+ch[6].CourseName;
break;
case 8:
return ch[7].CourseID+” “+ch[7].CourseName;
break;
case 9:
return ch[8].CourseID+” “+ch[8].CourseName;
break;
case 10:
return ch[9].CourseID+” “+ch[9].CourseName;
break;
default:
cout<<“Invalid decison!! Good Bye!”<<endl;
exit(0);
}
}

int creditTotal(int sel, course ch[])
{
switch(sel)
{
case 1:
return ch[0].numberOfCredits;
break;
case 2:
return ch[1].numberOfCredits;
break;
case 3:
return ch[2].numberOfCredits;
break;
case 4:
return ch[3].numberOfCredits;
break;
case 5:
return ch[4].numberOfCredits;
break;
case 6:
return ch[5].numberOfCredits;
break;
case 7:
return ch[6].numberOfCredits;
break;
case 8:
return ch[7].numberOfCredits;
break;
case 9:
return ch[8].numberOfCredits;
break;
case 10:
return ch[9].numberOfCredits;
break;
default:
cout<<“Invalid Decision!! Good Bye!”<<endl;
exit(0);
}
}

void fillSession(student arg[], course c[], session s[])
{
int c1, c2, c3, c4;
string ch1, ch2, ch3, ch4;
string startDate, endDate;
int cr1, cr2, cr3, cr4;

for (int i = 0; i < 4; i++)
{
for(int j = 0; j < 10; j++)
{
cout<<“class #”<<j+1<<” tt”<<c[j].CourseID<<” tt”<<c[j].CourseName<<” ttt”<<“Credits: “<<c[j].numberOfCredits<<“nn”;
}

cout<<“Enter your 1st class choice: “;
cin>>c1;
ch1=CourseN(c1,c);
cout<<“Enter your 2nd class choice: “;
cin>>c2;
ch2=CourseN(c2,c);
cout<<“Enter your 3rd class choice: “;
cin>>c3;
ch3=CourseN(c3,c);
cout<<“Enter your 4th class choice: “;
cin>>c4;
ch4=CourseN(c4,c);

s[i].courseID=ch1+”n”+ch2+”n”+ch3+”n”+ch4;
cout<<“Enter a start date for your classes (i.e mm/dd/yyyy): “;
cin>>startDate;
s[i].startDate=startDate;
cout<<“Enter a end date for your classes (i.e mm/dd/yyyy): “;
cin>>endDate;
s[i].endDate=endDate;

cr1=creditTotal(c1, c);
cr2=creditTotal(c2, c);
cr3=creditTotal(c3, c);
cr4=creditTotal(c4, c);

s[i].totalCredits=cr1+cr2+cr3+cr4;

c1=0;
c2=0;
c3=0;
c4=0;

system(“clear”);
}
}

void display_report(student s[], course c[], session se[])
{
for (int i = 0; i < 4; i++)
{
cout<<“Student ID: “<<s[i].stuID<<“n”<<endl;
cout<<“Student Name: “<<s[i].lname<<“, “<<s[i].fname<<“n”<<endl;
cout<<“Course IDs: n”<<se[i].courseID<<“n”<<endl;
cout<<“Start Date: n”<<se[i].startDate<<“n”<<endl;
cout<<“End Date: n”<<se[i].endDate<<“n”<<endl;
cout<<“Total Credits: “<<se[i].totalCredits<<“n”<<endl;
cout<<“n”<<endl;
}
}

/**
* Writes session data to file.
* @param   {session}   sess   sessions array.
*/
void writeSessionsToFile(session* sess)
{
ofstream file_out(“sessions.txt”);
// for now let us just assume there’ll always be just 4 sessions.
for (size_t i = 0; i < 4; ++i)
{
file_out << sess[i].sessionID << “n”;
file_out << sess[i].stuID << “n”;
file_out << sess[i].courseID << “n”;
file_out << sess[i].startDate << “n”;
file_out << sess[i].endDate << “n”;
file_out << sess[i].totalCredits << “n”;
// empty line in the end of each entry.
file_out << endl;
}
}

int main()
{
cout<<“Welcome to the CS 230 Data Structures class add program!”<<endl;
cout<<“Please follow the prompt to gain a report of your courses for the year: “<<endl<<endl;
//declare and initialize 4 students
student stu[4];
fillStudents(stu, 4);

//declare and initialize 10 courses
course courses[10];
fillCourses(courses, 10);

//assign 4 courses for each student
cout<<“Enter a class selection based on the chart above (1-10), please do not choose the same class twice: “<<endl;
cout<<“Each student goes by how their information was added”<<endl<<endl;

session sessions[4];
fillSession(stu, courses, sessions);

writeSessionsToFile(sessions);

//display a report showing each student with his/her courses
//show the total number of credits for each student
cout<<“Please find your name and other important information below to see your classes and credit totals: nn”<<endl;
cout <<“==========”<<endl;
display_report(stu, courses, sessions);
cout <<“==========”<<endl;

// instead of system(pause), pause doesn’t work on linux.
cin.get();
return 0;
}

Homework Ocean
Calculate your paper price
Pages (550 words)
Approximate price: -

Why Work with Us

Top Quality and Well-Researched Papers

We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.

Professional and Experienced Academic Writers

We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.

Free Unlimited Revisions

If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.

Prompt Delivery and 100% Money-Back-Guarantee

All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.

Original & Confidential

We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.

24/7 Customer Support

Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.

Essays

Essay Writing Service

No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.

Admissions

Admission Essays & Business Writing Help

An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.

Reviews

Editing Support

Our academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.

Reviews

Revision Support

If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. You can use this option as many times as you see fit. This is free because we want you to be completely satisfied with the service offered.

× Contact Live Agents