Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

So many Errors stopping my from moving forward

$
0
0
The I'm completely stuck and I dont know where to go from here. There are a lot of errors that I dont know how to fix

Project:
Implement a priority queue with a heap. The program would supply a menu to allow the
user to choose either to input a new entry to request computer CPU time or allow the
computer system to output the next name to use the system. For the input mode the user
would enter their name and a computer access priority (1 to 3 with 1 being the highest

Errors:
1>------ Build started: Project: Lab 3, Configuration: Debug Win32 ------
1>Build started 12/22/2012 3:04:37 PM.
1>InitializeBuildStatus:
1>  Creating "Debug\Lab 3.unsuccessfulbuild" because "AlwaysCreate" was specified.
1>ClCompile:
1>  Lab 7.cpp
1>g:\labs\lab 7\lab 7.cpp(16): error C2143: syntax error : missing ';' before '<'
1>          g:\labs\lab 7\lab 7.cpp(20) : see reference to class template instantiation 'HeapPriorityQueue<E,C>' being compiled
1>g:\labs\lab 7\lab 7.cpp(16): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>g:\labs\lab 7\lab 7.cpp(16): error C2238: unexpected token(s) preceding ';'
1>g:\labs\lab 7\lab 7.cpp(19): error C2143: syntax error : missing ';' before '<'
1>g:\labs\lab 7\lab 7.cpp(19): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>g:\labs\lab 7\lab 7.cpp(19): error C2238: unexpected token(s) preceding ';'
1>g:\labs\lab 7\lab 7.cpp(92): error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_string<_Elem,_Traits,_Alloc> &' from 'int'
1>          c:\program files\microsoft visual studio 10.0\vc\include\string(479) : see declaration of 'std::getline'
1>g:\labs\lab 7\lab 7.cpp(92): error C2780: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : expects 3 arguments - 2 provided
1>          c:\program files\microsoft visual studio 10.0\vc\include\string(468) : see declaration of 'std::getline'
1>g:\labs\lab 7\lab 7.cpp(92): error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &&,std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_string<_Elem,_Traits,_Alloc> &' from 'int'
1>          c:\program files\microsoft visual studio 10.0\vc\include\string(448) : see declaration of 'std::getline'
1>g:\labs\lab 7\lab 7.cpp(92): error C2780: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &&,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : expects 3 arguments - 2 provided
1>          c:\program files\microsoft visual studio 10.0\vc\include\string(395) : see declaration of 'std::getline'
1>g:\labs\lab 7\lab 7.cpp(96): error C2065: 'test' : undeclared identifier
1>g:\labs\lab 7\lab 7.cpp(96): error C2228: left of '.last' must have class/struct/union
1>          type is ''unknown-type''
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.10
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



Code:
#include<iostream>
#include<string>
using namespace std;

template <typename E, typename C>
class HeapPriorityQueue {
public:
	HeapPriorityQueue();
	int size() const;
	bool empty() const;
	void insert(const E& e);
	const E& min();
	void removeMin();
	
private:
	VectorCompleteTree<E> T;
	C isLess;

	typedef typename VectorCompleteTree<E>::Positiion Postiition;
};

template <typename E, typename C> //number of elements
int HeapPriorityQueue<E,C>::size() const 
{
	return T.size();
}

template <typename E, typename C> //is the queue empty?
bool HeapPriorityQueue<E,C>::empty() const 
{
	return size() == 0;
}

template <typename E, typename C> //mininum element
const E& HeapPriorityQueue<E,C>::min()
{
	return *(T.root());			// return reference to root element
}

template <typename E, typename C> //insert element
void HeapPriorityQueue<E,C>::insert(const E& e)
{
	T.addLast(e);				//add e to heap
	Position v = T.last();		//e's position
	while (!T.isRoot(v)) {		//up-heap bubbling
	}
	Position u = T.parent(v);
	if (!isLess(*v, *u)) break;	//uf v is in order, done
	T.swap(v, u,);			// else swap with parent
	v =u;
}

template <typename E, typename C> //remove min
void HeapPriorityQueue<E,C>::removeMin()
{
	if (size() == 1) //onle one node?
	{
		T.removeLast(); //remove it
	}
	else {
		Position v = T.root();		//root position
		T.swap(u, T.last());		//swap last with root
		T.removeLast();				//remove last
		while (T.hasLeft(u)) {		//down-heap bubbling
			Position v = T.left(u);
			if (T.hasRight(u) && isLess(*(T.right(u)), *v))
				v = T.right(u);		//v is u's smaller child
			if (isLess(*v,*u)) {	//is u out of order?
				T.swap(u, v);		//then swap
				u = v;
			}
			else break;
		}
	}
}

int main(){

	int name;
	int option = 1;
	while(option)
	{
		cout<<"Add your name onto the CPU usage waiting list - Enter 1"<<endl;
		cout<<"Who is next? - Enter 2"<<endl;
		
		cin>>option;
		switch(option)
		{
		case 1:
			cout<<"Please enter your last name"<<endl;
			cin.ignore();
			getline(cin, name);
			
			break;
		case 2:
			cout << test.last() << "Is Next" << endl;
			break;
		}
	}
	return 0;
}




Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>