Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

So when I compile the following code in unix I get no errors...Then when I try t

ID: 3622428 • Letter: S

Question

So when I compile the following code in unix I get no errors...Then when I try to execute it I get the following:


./heap_student_data1.cpp: line 10: using: command not found
./heap_student_data1.cpp: line 12: syntax error near unexpected token `('
./heap_student_data1.cpp: line 12: `int main(void)'

Here is my code:
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string.h>
#include <stdlib.h>

#include "heap_student.cpp"

using namespace std;

int main(void)

{
int num_of_students;
char temp[200];
char temp2[220];
char *tokenptr ;
string student_index ;

ifstream infile;

infile.open ("student_data.dat");
if (infile.is_open())
{
cout << "Successful opening file to count records" << endl;
num_of_students = 0 ;

while (infile.good() )
{
if (infile.getline(temp,200))

{
num_of_students++ ;
cout << temp << endl ;
}
}

cout << "Number of Students are: " << num_of_students << endl ;
}

else
{
cout << "Error opening file";
}

infile.close();

// 2nd pass at file file student array

Student *student_info = new Student[num_of_students] ;

char first_name[20] = " ";
char last_name[35] = " ";
char addr_1[35] = " " ;
char addr_2[35] = " " ;
char city[20] = " ";
char state[3]= " ";
char zip_code[7] = " ";

string first_name_str ;
string last_name_str;
string addr_1_str ;
string addr_2_str;
string city_str;
string state_str ;
string zip_code_str ;

int birth_day_month;
int birth_day_day;
int birth_day_year;
int comp_date_month;
int comp_date_day;
int comp_date_year;
double gpa;
int credit_hours_completed ;

int count, i1, i2, sindex ;

infile.open ("student_data.dat");
if (infile.is_open())
{
cout << "Successful opening file to obtain records" << endl;

sindex = 0 ;

if (infile.good()) infile.getline(temp,200) ;

while (infile.good() )
{

// cout << temp << endl;

count = strlen(temp);


// cout << count << endl;

// The following code inserts a space between any blank entry (between commas) to insure all fields get filled properly

count++;
i1 = 0;
i2 = 0;

while ( count-- )

{

if (temp[i1] == ',' && temp[i1+1] == ',')

{
temp2[i2] = temp[i1] ;
temp2[i2+1] = ' ';
i2++ ;
}
else
{
temp2[i2] = temp[i1] ;
}
i1++; i2++;
}

// cout << temp2 << endl ;

if (tokenptr = strtok(temp2,",") )
{
strcpy(first_name,tokenptr) ;
first_name_str.assign(first_name) ;
// cout << first_name_str << endl ;
}

if (tokenptr = strtok(NULL,",") )
{
strcpy(last_name,tokenptr) ;
last_name_str.assign(last_name) ;
// cout << last_name << endl ;
}


if (tokenptr = strtok(NULL,","))
{
strcpy(addr_1,tokenptr) ;
addr_1_str.assign(addr_1) ; // cout << addr_1 << endl ;
// cout << addr_1_str << endl ;
}


if (tokenptr = strtok(NULL,","))
{
strcpy(addr_2,tokenptr) ;
addr_2_str.assign(addr_2) ;
// cout << addr_2 << endl ;
}


if (tokenptr = strtok(NULL,","))
{
strcpy(city,tokenptr) ;
city_str.assign(city) ;
// cout << city << "in tokenptr city" << endl ;
}


if (tokenptr = strtok(NULL,","))
{
strcpy(state,tokenptr) ;
state_str.assign(state) ;
// cout << state_str << "in tokenptr state" << endl ;
}


if (tokenptr = strtok(NULL,","))
{
strcpy(zip_code,tokenptr) ;
zip_code_str.assign(zip_code) ;
// cout << zip_code << endl ;
}

if (tokenptr = strtok(NULL,","))
birth_day_month = atoi(tokenptr);

// cout << birth_day_month << endl ;

if (tokenptr = strtok(NULL,","))
birth_day_day = atoi(tokenptr);

// cout << birth_day_day << endl ;

if (tokenptr = strtok(NULL,","))
birth_day_year = atoi(tokenptr);
// cout << birth_day_year << endl ;

if (tokenptr = strtok(NULL,","))
comp_date_month = atoi(tokenptr);
// cout << comp_date_month << endl ;

if (tokenptr = strtok(NULL,","))
comp_date_day = atoi(tokenptr);
// cout << comp_date_day << endl ;

if (tokenptr = strtok(NULL,","))
comp_date_year = atoi(tokenptr);
// cout << comp_date_year << endl ;

if (tokenptr = strtok(NULL,","))
gpa = atof(tokenptr);
// cout << gpa << endl ;

if (tokenptr = strtok(NULL,","))
credit_hours_completed = atoi(tokenptr);
// cout << credit_hours_completed << endl ;

// cout << temp << endl ;


student_index = student_info[sindex].set_student(first_name_str,last_name_str,
Address(addr_1_str,addr_2_str,city_str,state_str,zip_code_str),
Date(birth_day_month,birth_day_day,birth_day_year),
Date(comp_date_month,comp_date_day,comp_date_year),
gpa,credit_hours_completed) ;

cout << student_index << endl ;


sindex++ ;

infile.getline(temp,200) ;

} // end infile while

infile.close();
}
else
{
cout << "Error opening file";
}

// Add print routines and sort routines for student array student_info


cout << "Entering sort routine" << endl ;
// Sort student_info


bool swapsw = true;
string string1 ;
string string2 ;
Student tmp_student ;

while (swapsw)

{
i1 = 0;
swapsw = false;

while (i1 < num_of_students-1)

{
string1 = student_info[i1].get_student() ;
string2 = student_info[i1+1].get_student() ;

// cout << string1 << endl ;
// cout << string2 << endl ;

if (string1.compare(string2) > 0 )
{
tmp_student = student_info[i1] ;
student_info[i1] = student_info[i1+1] ;
student_info[i1+1] = tmp_student;
swapsw = true;
// cout << "In Swap" << endl ;


}

i1++ ;

} // while loop through array

} // end swapsw check

cout << "Entering Print Array Routine to check sort order last name - first name" << endl ;
// Check array

i1 = 0;

while (i1 < num_of_students)

{

cout << student_info[i1].get_student() << endl;
i1++ ;

} // while loop through array for checking sort


// Routine to print formatted report - later move logic to print lines to a call to student class ;


cout << "Entering Print Routine to create formatted report -- See printfile.txt " << endl ;


ofstream myfile;
myfile.open ("print_file.txt");
// myfile << "Writing this to a file. ";



// Print out report header

myfile << student_info[i1].get_student_rpt_hd() << endl;

i1 = 0;

while (i1 < num_of_students)

{
myfile << student_info[i1].get_student_rpt_line() << endl;
i1++ ;

} // while loop through array for printing report lines

myfile.close();

// release memory for student array

delete [] student_info ;

// Create formatted report ;

return 0;



// student_info.get_num_of_students("student_data.dat") ;

}


// #include "heap_address.cpp"
// #include "heap_date.cpp"
// #include "heap_student.cpp"


Explanation / Answer

Did you properly complie it. You have tried to execute the cpp file and not executable file. Complie using g++ . A file named a.out will be generated. Run the prog using ./a.out command.
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote