When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
46 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
test students;
int studentNum;
cout << "How many students will you be entering for? " << endl;
cin >> studentNum;
test *arr = new test(students);
that is what I have so far and I know its sloppy but it is confusing tf outta me
it is not having issues in the compiler but it looks... wrong to me
are there 2 or more constructors, one without a argument and one with the argument test?
yes would you like me to post the header file?
ye sure.
#include <string>
class test {
private:
std::string firstName;
std::string lastName;
double test1;
double test2;
double test3;
public:
test();
test(std::string firstName, std::string lastName, double test1, double test2, double test3);
void setfirstName(std::string first_name);
std::string getfirstName();
void setlastName(std::string last_name);
std::string getlastName();
void setTest1(double test_1);
double getTest1();
void setTest2(double test_2);
double getTest2();
void setTest3(double test_3);
double getTest3();
double calcAverage();
};
/*******************************
* CONSTRUCTOR *
*******************************/
test::test(){
firstName = "John";
lastName = "Doe";
test1 = 100.0;
test2 = 100.0;
test3 = 100.0;
}
test::test(std::string nameFirst, std::string nameLast, double firstTest, double secondTest, double thirdTest) {
firstName = nameFirst;
lastName = nameLast;
test1 = firstTest;
test2 = secondTest;
test3 = thirdTest;
}
void test::setfirstName(std::string first_name) {
firstName = first_name;
}
std::string test::getfirstName() {
return firstName;
}
void test::setlastName(std::string last_name) {
lastName = last_name;
}
std::string test::getlastName() {
return lastName;
}
void test::setTest1(double test_1) {
test1 = test_1;
}
double test::getTest1() {
return test1;
}
void test::setTest2(double test_2) {
test2 = test_2;
}
double test::getTest2() {
return test2;
}
void test::setTest3(double test_3) {
test3 = test_3;
}
double test::getTest3() {
return test3;
}
double test::calcAverage() {
return (test1 + test2 + test3) / 3;
}```
(I am sure you can already tell I am still a beginner)
haha
why are you calling it arr?
array
ye ik why
I am just trying to create an array of students from my class type, but making it dynamically as the initial number of students is unknown
why aren't you using std::vector<T> then?
we are not using vectors yet
ah alright
ye my teacher has an "interesting" method of teaching
nah for some reason all university's do that
that is what i have been hearing, especially with "using namespace std"
lol
nvm i was a bit confused
yeah its kinda sloppy my bad
nah its not bec of that
but the this code is fine for now
depends on what you wanna do
with it later
no this isn't dynamicly resizable
ye ik
but there is nothing coded here wich makes it dynamically resizable
sadly
yes you have said that
its alright man ill just figure it out myself, thanks for the attempt.
!solved
Thank you and let us know if you have any more questions!
@burnt echo
Please don't delete forum posts. They can be helpful to refer to later and other members can learn from them. You can use !solved to close a post and mark it as solved.
@burnt echo here i made this resizable class to give you a idea of what to do
class V
{
V* Next;
int val;
public:
V(int val) : val(val) {}
int operator[](int Pos)
{
int currpos{0};
V* Temp = this;
if (currpos == Pos)return Temp->val;
while (Next)
{
currpos++;
Temp = Temp->Next;
if (currpos == Pos)return Temp->val;
}
return 0;
}
void push_back(int val)
{
V* Temp = this;
while (Next)Temp = Temp->Next;
V* next = new V(val);
Temp->Next = next;
}
};
ah wait it has some issues
alr fixed
;compile
#include <iostream>
class V
{
V* Next;
int val=0;
public:
V(int val) : val(val) {}
V() = default;
int operator[](int Pos)
{
int currpos{ 0 };
V* Temp = this->Next;
if (currpos == Pos)
return Temp->val;
while (Temp->Next)
{
currpos++;
Temp = Temp->Next;
if (currpos == Pos)return Temp->val;
}
return 0;
}
void push_back(int val)
{
V* Temp = this;
while (Temp->Next)Temp = Temp->Next;
V* next = new V(val);
Temp->Next = next;
}
};
int main()
{
V myvec;
for (int i = 0; i < 5; i++)myvec.push_back(i);
for (int i = 0; i < 5; i++)std::cout << myvec[i] << "\n";
}
0
1
2
3
4