my professor gave a .o file and we are supposed to write a function that links to his file in ssh.
his code is

struct grades
{ int lab;
int prog;
int mid;
int final;
char name[10];
}

void fillArray(grades a[ ], int & num);


these two are given and i am supposed to write a c++ in linux that reads the file and calculate final grade for each students where there are 50 students.
my code is so far

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

struct grades
{
int lab;
int prog;
int mid;
int final;
char name[10];
};


void printScore(grades[], const int);
void fillArray(grades a[ ], int & num);

int main()
{
int countStd;
ifstream fin;
fin.open("lab2.o"); //read txt file
if(fin==NULL)
cout<<"Error";
fin>>countStd;
// cout<<countStd;
for(int i=0; i< countStd; i++)
{
string name;
int lab, prog, mid, final;
fin >> name >> lab >> prog >> mid >> final;
fillArray(grades[i], name, lab, prog, mid, final);
}
printScore(grades,countStd);

return 0;

}
void fillArray(grades& a, const string name, const int s1, const int s2, const int s3, const int s4)
{
s.name = name;
s.lab = s1;
s.prog = s2;
s.mid = s3;
s.final= s4;
s.finalgrade = s1*(.2)+s2*(.2)+s3*(.3)+s4*(.3);

}//storeScore

void printScore(grades a[],const int count)
{
cout<<"\tname \t"<<"\tquiz"<<"\tlab"<<"\tmid"<<"\tfina…
cout<<"*********************************…
for(int i=0; i<count; i++)
{
cout<<a[i].name<<"\t"<<a[i].lab<<"\t"<<a…
cout<<a[i].mid<<"\t"<<a[i].final<<"\t"<<…
}//for
}//printScore

and I get many errors.

can anybody help me with this?

>> my professor gave a .o file and we are supposed to write a function that links to his file in ssh.

Terminology is important. I assume "ssh" means "secure shell". ".o" file means "object code". "Links to his file" means link the object code. "In ssh" doesn't really mean anything. None of that appears to relate to your code.

If the assignment is read a text file that your professor gave you, then "ssh" is irrelevant and you should probably call it "lab2.txt" rather than "lab2.o". I don't see where any "linking" is done or where "ssh" is used.


>> and I get many errors.

What are they? I assume the compile doesn't know what the variable "s" refers to in fillArray. I also see a redefinition of fillArray. Is this taking an array or is it taking a single object passed by reference? Plus the number of arguments has changed. Compilers don't like that.

I also see no grades object declared anywhere, so it's hard to pass it to the function.

first off, yes all the terms are like you understood. After I finish, I am supposed to use
g++ -o myprogram.cpp lab2.o myname.o
this command in ssh to perform "linking" these two.

first off, yes all the terms are like you understood. After I finish, I am supposed to use
g++ -o myprogram.cpp lab2.o myname.o
this command in ssh to perform "linking" these two.

There's nothing to link. Neither main nor any function called in your program refers to anything that isn't already in your single C++ program. Hence no need for linking to another .o file that your professor provided.

If lab2.o is an object file, why are opening it and trying to read data from it in your C++ file? You also have a comment saying "read txt file". lab2.o is either an object code file or a text file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.