Find my bug. C++ programming exercise [closed] - c++

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
#ifndef _SOLDIER_H_
#define _SOLDIER_H_
#include <iostream>
#include <stack>
using namespace std;
class Soldier {
// your code here
private:
stack<int> list;
public:
Soldier(int num);
bool check(vector<int> arrange);
};
#endif
Error is at the above Soldier.h, at bool check(vector arrange);
15 C:\Users\king boon\Desktop\CS1020E\lab4\lab4\ex1\skeleton\Soldier.h expected `;' before '(' token
#include "Soldier.h"
// your code here
Soldier::Soldier(int num) {
int i;
for (i=1; i<=num; i++) {
list.push(i);
}
};
bool Soldier::check(vector<int> arrange) {
return true;
};
Been trying for hours, at my wits end. Thanks.

vector isn't declared:
#include <vector>

Related

In c++ if header is included why I got 'does not a name of type' error? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I have data.h:
#ifndef DATA_H_INCLUDED
#define DATA_H_INCLUDED
#include <vector>
#include <string>
#include <iostream>
using namespace std;
class student{
public:
string id;
int points [6] = {0,0,0,0,0,0};
};
#endif // DATA_H_INCLUDED
And I have enor.h:
#ifndef ENOR_H_INCLUDED
#define ENOR_H_INCLUDED
#include <fstream>
#include <vector>
#include <string>
#include <iostream>
#include "data.h"
using namespace std;
enum status{norm,abnorm};
class enor{
public:
/*some voids*/
Student Current() const { return elem; }
student elem;
private:
/*some voids*/
};
#endif // ENOR_H_INCLUDED
And I got 'Student' does not a name a type, but why? I tried also if the Student calss is in enor.h, but also this error. how can I resolve this, and why is this?
You have a difference in your case for your student class:
class student - Lower case s
Student Current() const - Upper case S

"{" missing function header (old style format list) - expected a declaration [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I'm really really new to C++ and this is my first program on Visual Studio 2015, It shows me 2 errors:
"{" missing function header (old style format list)
expected a declaration
#include "stdafx.h"
#include <iostream>
int main();
{
cout << "Hello World";
return 0;
}
int main() remove ; at the end.
#include "stdafx.h"
#include <iostream>
int main(); // this ';' is giving problem remove it.
{
std::cout << "Hello World"; // use std::cout
return 0;
}

Having trouble with the error: expected unqualfied-id before '{' just a header for a class that I need just not sure what is causing the error [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
#include <iostream>
using namespace std;
{
class book
{
public:
set_book();
show_book();
private:
string title,author;
int pages,date;
};
}
In addition to the points made by other answers...
You have:
set_book();
show_book();
These are not valid member function declarations. They need, at the least, a return type.
void set_book();
void show_book();
Please add any input arguments needed by them.
You are missing includes (string), you should avoid using namespace std in a header.
And also, remove this extra scope :
using namespace std;
// { <------
class book
{
public:
set_book();
show_book();
private:
string title,author;
int pages,date;
};
// } <------
You have a bogus set of { and }.
Change to:
#include <iostream>
using namespace std; // this is a bad idea BTW
class book
{
// etc.
Also it'd be a good idea to #include <string> in case whoever includes your file does not include that; and if you don't actually use iostream then don't include it.

Cant call functions when placing class in seperate file [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
So Im new to C++, im trying to create a function to calculate the area of a triangle when the user inputs the base and height, however whenever i try to build and run this program I get an error saying: ISO C++ forbids declaration of "calcArea" with no type [-fpermissive]
Area.h
#ifndef AREA_H
#define AREA_H
#include <iostream>
using namespace std;
class Area
{
private:
int base;
int height;
public:
Area();
int calcArea();
};
#endif // AREA_H
Area.cpp
#include "Area.h"
#include <iostream>
using namespace std;
Area::Area()
{
cin >> base;
cin >> height;
};
Area::calcArea(){
int answer;
answer = base * height;
return answer;
}
You are missing the return type.
int Area::calcArea(){
//^^^
Your current
Area::calcArea(){
int answer;
...
definition misses to specify a return type matching the declaration int calcArea(); from your Area class declaration.
As T.C. already showed it needs to be
int Area::calcArea(){
//^^^
int answer;
...

programme crashes when trying to cout map value [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I am trying to insert pair values < float,string > into my map class
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <set>
#include <iostream>
#include <map>
using namespace std;
int main()
{
map<float,string> output;
output.insert(pair<float,string> ( 200.5, "foo" ));
output.insert(pair<float,string> ( 100.5, "batr" ));
map<float,string>::iterator mps1;
map<float,string>::iterator mps2;
mps1 = output.begin();
mps2 = output.end();
while (mps1 != mps2)
{
cout<<mps2->first
<<" "
<<mps2->second; //crashes here
mps1++;
}
system("PAUSE");
}
Using the debugger , it crashes when it does to the following line
<<mps2->second;
Can someone explain to me , thanks
You're supposed to access mps1, not mps2.
mps1 is the iterator you're incrementing for use; mps2 is the "end iterator" which you must not dereference.
It's a pretty basic typo / logic error.