#include <iostream>
#include <sstream>
#include <vector>
#include <fstream>
using namespace std;
struct Unit
{
string code;
int numberOfCreditHours;
int semester;
int numberOfPreReq;
vector<string> prerequisties;
int numberOfPostReq;
vector<string> postrequisties;
};
vector<string> split (const string &s, char delim)
{
vector<string> result;
stringstream ss (s);
string item;
while (getline (ss, item, delim)) {
result.push_back (item);
}
return result;
}
int main() {
vector<string> v;
vector<string> requesties;
Unit units[20];
int credithours;
int semester;
int line = 0;
string req;
ifstream file("thefile.txt");
// Processing the data in the text file to the vector of String.
// Opening the file
if (file.is_open()) {
string sample;
while (getline(file, sample)) {
v = split (sample, ';');
units[line].code = v[0];
units[line].numberOfCreditHours = stoi(v[1]);
units[line].semester = stoi(v[2]);
req = v[3];
requesties = split(req,',');
units[line].numberOfPreReq = requesties.size();
units[line].prerequisties = requesties;
req = v[4];
requesties = split(req,',');
units[line].numberOfPostReq = requesties.size();
units[line].postrequisties = requesties;
line++;
}
}
// Closing the file
file.close();
//Printing them into the console
for(int i=0; i<line; i++){
cout<<"Details of unit "<<i+1<<endl;
cout<<"Unit code is "<<units[i].code<<endl;
cout<<"Number of credit Hours of unit is
"<<units[i].numberOfCreditHours<<endl;
cout<<"Number of Semester of unit is
"<<units[i].semester<<endl;
cout<<"Number of preRequities of unit is
"<<units[i].numberOfPreReq<<endl;
cout<<"Prerequesties are "<<endl;
for(int j=0; j<units[i].prerequisties.size(); i++)
cout<<units[i].prerequisties[j]<<endl;
cout<<"Number of postRequities of unit is
"<<units[i].numberOfPostReq<<endl;
cout<<"Postrequesties are "<<endl;
for(int j=0; j<units[i].postrequisties.size(); i++)
cout<<units[i].postrequisties[j]<<endl;
}
return 0;
}
If you left with any doubts..feel free to ask.
1. Define Structure UNIT as described in the list: ınit char codease complete the question int...
Activities Define a struct called Unit containing the following fields I Unit code Unit credit hours Unit semester of study List of prerequisites Number of prerequisites List of post requisites Number of post requisites Inside your main function declare an array of type Unit called units with size 20 elements. This array will contain the information related to all the units in our diploma program. Each of the elements of this array correspond with one our diploma units. II III...
IN C ONLY As mentioned earlier there are two changes we are going to make from lab 5, The file you read into data structures can be any length. studentInfo array will be stored in another struct called studentList that will contain the Student pointer and current length of the list. Sometimes data can be used in structs that correlate between variables so it's convenient to store the data in the same struct. Instead of tracking a length variable all...
C programming The program will require the following structure: struct _data { char *name; long number; }; The program will require command line arguments: int main(int argv, char **argc) { Where argv is the number of arguments and argc is an array holding the arguments (each is a string). Your program must catch any case where no command line arguement was provided and print a warning message (see below). You MUST include/use the following functions, defined as follows: int SCAN(FILE...
// Write the compiler used: Visual studio // READ BEFORE YOU START: // You are given a partially completed program that creates a list of patients, like patients' record. // Each record has this information: patient's name, doctor's name, critical level of patient, room number. // The struct 'patientRecord' holds information of one patient. Critical level is enum type. // An array of structs called 'list' is made to hold the list of patients. // To begin, you should trace...
Hello! I'm posting this program that is partially completed if someone can help me out, I will give you a good rating! Thanks, // You are given a partially completed program that creates a list of employees, like employees' record. // Each record has this information: employee's name, supervisors's name, department of the employee, room number. // The struct 'employeeRecord' holds information of one employee. Department is enum type. // An array of structs called 'list' is made to hold...
DO NOT use #include <cstdlib> , iterate, and list. USE pointers and arrays. 1.Define a class named Family in a header file named: family.h (5 points) This file acts as a prototype. 2.Create the implementation file family.cpp (15 points total) a.The class will have the following members 1.Family name (5 points) 2. Parent (array of 2) (5 points) a.First Name b.Last Name c. Age (you must validate the age is the proper data type. You can use the code from...
C++ program that reads students' names followed by their test scores (5 scores) from the given input file, students.txt. The program should output to a file, output.txt, each student's first name, last name, followed by the test scores and the relevant grade. All data should be separated by a single space. Student data should be stored in a struct variable of type StudentType, which has four components: studentFName and studentLName of type string, an array of testScores of type int...
Write the functions needed to complete the following program as described in the comments. Use the input file course.txt and change the mark of student number 54812 to 80. /* File: course.cpp A student's mark in a certain course is stored as a structure (struct student as defined below) consisting of first and last name, student id and mark in the course. The functions read() and write() are defined for the structure student. Information about a course is stored as a...
Assignment 1 In this assignment you will be writing a tool to help you play the word puzzle game AlphaBear. In the game, certain letters must be used at each round or else they will turn into rocks! Therefore, we want to create a tool that you can provide with a list of letters you MUST use and a list of available letters and the program returns a list of all the words that contain required letters and only contain...
// READ BEFORE YOU START: // You are given a partially completed program that creates a list of students for a school. // Each student has the corresponding information: name, gender, class, standard, and roll_number. // To begin, you should trace through the given code and understand how it works. // Please read the instructions above each required function and follow the directions carefully. // If you modify any of the given code, the return types, or the parameters, you...