| | |
help with namespace error
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2005
Posts: 15
Reputation:
Solved Threads: 0
Im getting some interesting error messages when i try to compile my program here is the error messages:
expected unqualified-id before "namespace"
expected `,' or `;' before "namespace"
expected namespace-name before ';' token
'<type error>' is not a namespace
Here is my code...any help would be greatly appreciated
#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;
ifstream inData;
ofstream outData;
bool die = 1;
bool sorted = 0;
int main()
{
char choice;
float T[100];
while(die)
{
cin.clear();
Arwork :: Get_Choice(choice); //calls the menu function
Arwork :: Process_Choice(T[],choice);
}
}
void Arwork:: Get_Choice(char choice)
{
outData<<endl;
cout<< "The following is the menu" << endl;
outData<<"The following is the menu" << endl;
cout<<endl;
outData<<endl;
cout<< "a. Load the array" << endl;
outData<< "a. Load the array" << endl;
cout<< "b. Sort the Array in ascending order" << endl;
outData<< "b. Sort the Array in ascending order" << endl;
cout<< "c. Average the Numbers" << endl;
outData<< "c. Average the Numbers" << endl;
cout<< "d. Find the smallest number" << endl;
outData<< "d. Find the smallest number" << endl;
cout<< "e. Find the largest number" << endl;
outData<< "e. Find the largest number" << endl;
cout<< "f. Search for a Number" <<endl;
outData<< "f. Search for a Number" <<endl;
cout<< "g. Check how many numbers are between two numbers" <<endl;
outData<< "g. Check how many numbers are between two numbers" <<endl;
cout<< " ENTER z TO QUIT " << endl;
outData<< " ENTER z TO QUIT " << endl;
cout<< "Enter your choice"<< endl;
outData<< "Enter your choice"<< endl;
cin >> choice;
}
void Arwork:
rocess_Choice(float T[],char choice,int size)
{
float y = 0;
switch(choice)
{
case 'a':
Load(T,size);
display_Array(T,size);
break;
case 'b': Sort(T,size);
cout<<"Sorted Array: "<<endl;
outData<<"Sorted Array: "<<endl;
display_Array(T,size);
break;
case 'c':cout<<"Average: ";
outData<<"Average: ";
y = Average(T,size);
cout<<y<<endl;
outData<<y<<endl;
break;
case 'd': cout<<"Largest Number in Array: ";
outData<<"Largest Number in Array: ";
y = LargestNum(T,size);
cout<<y<<endl;
outData<<y<<endl;
break;
case 'e': cout<<"Smallest Number in Array: ";
outData<<"Smallest Number in Array: ";
y = SmallestNum(T,size);
cout<<y<<endl;
outData<<y<<endl;
break;
case 'f': cout<< "The number is at position(s): ";
outData<< "The number is at position(s): ";
y = Search(T,size);
cout<<y<<endl;
outData<<y<<endl;
break;
case 'g': cout<<"Numbers between: "<<
outData<<"Numbers between: ";
y = Between(T,size);
cout<<y<<endl;
outData<<y<<endl;
break;
case 'h': cout<<"Insertion of Number Array: "<<endl;
outData<<"Insertion of Number Array: "<<endl;
Insertion(T,size);
display_Array(T,size);
break;
case 'i': cout<<"New Array after Deleted Number: "<<endl;
outData<<"New Array after Deleted Number: "<<endl;
Delete(T,size);
display_Array(T,size);
break;
case 'z': cout<<"EXIT"<<endl;
die = 0;
break;
default:
cout<<"INVAILD ENTRY"<<endl;
outData<<"INVAILD ENTRY"<<endl;
break;
}
}
void Arwork :: Load(float T[100],int size)
{
char answ;
//prompts the user for keyboard of file input
cout<< "Would you like to input from File or Keyboard" << endl;
cout<< "Enter 'f' or 'k'" << endl;
cin>> answ;
//Keyborad input
if(answ == 'k')
{
cout<< "Enter all the data at once or (Ctrl-Z to quit)" << endl;
outData<< "Enter all the data at once or (Ctrl-Z to quit)" << endl;
int i =0;
while(cin)
{
cin >> T[i];
outData<< T[i]<< " ";
if(cin) i++;
size++;
}
size = size-1;
}
else
{
//file input
string fileName;
cin.clear();
cout<< "Input file name, then press Ctrl-D, Enter" << endl;
outData<< "Input file name, then press Ctrl-D, Enter" << endl;
cin >> fileName;
inData.open(fileName.c_str());
int i=0;
for (int i = 0; inData>> T[i]; i++)
++size;
size = size-1;
}
}
//sorts the array
void Arwork :: Sort(float T[100], int size)
{
int i, j, smallestAt;
for (int i = 0 ; i < size - 1 ; i++)
{
smallestAt = i;
for (j = i + 1 ; j < size ; j++)
{
if (T [j] < T[smallestAt])
{
smallestAt = j;
}
}
//calls swap
if (smallestAt != i)
{
swap (i, smallestAt, T);
}
}
sorted = true;
}
//swaps the numbers in the array
void Arwork :: swap (int loc1, int loc2,float T[])
{
float temp = T [loc1];
T [loc1] = T [loc2];
T [loc2] = temp;
}
//computes the average
float Arwork:: Average(float T[100], int size)
{
float total = 0.0;
for(int k = 0;k< size;k++)
{
total += T[k];
}
cout<<total/size<<endl;
outData<<total/size<<endl;
return total/size;
}
//finds the smallest number
float Arwork :: SmallestNum(float T[],int size)
{
float min = 0.0;
for(int k = 0;k< size;k++)
{
if(T[k]<min)
{
min = T[k];
}
}
cout<<min<<endl;
outData<<min<<endl;
return min;
}
//finds the largest integer
float Arwork :: LargestNum(float T[100], int size)
{
float max = 0.0;
for(int k = 0;k< size;k++)
{
if(T[k] > max)
{
max = T[k];
}
}
cout<<max<<endl;
outData<<max<<endl;
return max;
}
//inserts a number in an array
void Arwork :: Insertion(float T[100],int size)
{
float target = 0.0;
cout<<"Enter the number you are inserting"<<endl;
outData<<"Enter the number you are inserting"<<endl;
cin>>target;
int k=0;
while((k< size) && (T[k] < target))
k++;
for(int index = size -1; index>=k;index --)
{
T[index + 1] = T[index];
}
T[k] = target;
size = size + 1;
}
//deletes a number in an array
void Arwork :: Delete(float T[100],int size)
{
float target = 0;
cout<< "Enter the number you wish to delete" <<endl;
outData<<"Enter the number you wish to delete" <<endl;
cin>>target;
int k=0;
while((k<size) && (T[k] != target))
k++;
for(int index = k+1; index < size; index++)
T[index -1] = T[index];
size++;
}
//finds a number in an array
int Arwork :: Search(float T[100], int size)
{
int num;
if(sorted == true)
{
float target = 0;
cout<< "Enter the number you wish to search for:" <<endl;
outData<< "Enter the number you wish to search for:" <<endl;
cin>>target;
int k=0,h=0;
for(h=0;h<size;h++)
{
if(T[h] == target)
return h;
}
}
else
{
cout<<"ARRAY NEEDS TO BE SORTED FIRST"<<endl;
outData<<"ARRAY NEEDS TO BE SORTED FIRST"<<endl;
}
return 0;
}
//counts how many values are between two numbers
float Arwork :: Between(float T[100], int size)
{
int k = 0;
int j = 0;
float num1,num2;
cout<< "Enter your First Number then press Enter" <<endl;
outData<< "Enter your First Number then press Enter" <<endl;
cin>> num1;
cout<< "Enter your Second Number then press Enter" <<endl;
outData<< "Enter your Second Number then press Enter" <<endl;
cin>> num2;
for(k=0;k > size;k++)
{
if((T[k]>num1)&&(T[k]<num2))
cout<<T[k];
}
return j;
}
//displays the array
void Arwork :: display_Array(float T[100], int size)
{
int k =0;
for(k = 0;k<size;k++)
cout<<T[k]<<" ";
cout<< " "<<endl;
}
expected unqualified-id before "namespace"
expected `,' or `;' before "namespace"
expected namespace-name before ';' token
'<type error>' is not a namespace
Here is my code...any help would be greatly appreciated
#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;
ifstream inData;
ofstream outData;
bool die = 1;
bool sorted = 0;
int main()
{
char choice;
float T[100];
while(die)
{
cin.clear();
Arwork :: Get_Choice(choice); //calls the menu function
Arwork :: Process_Choice(T[],choice);
}
}
void Arwork:: Get_Choice(char choice)
{
outData<<endl;
cout<< "The following is the menu" << endl;
outData<<"The following is the menu" << endl;
cout<<endl;
outData<<endl;
cout<< "a. Load the array" << endl;
outData<< "a. Load the array" << endl;
cout<< "b. Sort the Array in ascending order" << endl;
outData<< "b. Sort the Array in ascending order" << endl;
cout<< "c. Average the Numbers" << endl;
outData<< "c. Average the Numbers" << endl;
cout<< "d. Find the smallest number" << endl;
outData<< "d. Find the smallest number" << endl;
cout<< "e. Find the largest number" << endl;
outData<< "e. Find the largest number" << endl;
cout<< "f. Search for a Number" <<endl;
outData<< "f. Search for a Number" <<endl;
cout<< "g. Check how many numbers are between two numbers" <<endl;
outData<< "g. Check how many numbers are between two numbers" <<endl;
cout<< " ENTER z TO QUIT " << endl;
outData<< " ENTER z TO QUIT " << endl;
cout<< "Enter your choice"<< endl;
outData<< "Enter your choice"<< endl;
cin >> choice;
}
void Arwork:
rocess_Choice(float T[],char choice,int size){
float y = 0;
switch(choice)
{
case 'a':
Load(T,size);
display_Array(T,size);
break;
case 'b': Sort(T,size);
cout<<"Sorted Array: "<<endl;
outData<<"Sorted Array: "<<endl;
display_Array(T,size);
break;
case 'c':cout<<"Average: ";
outData<<"Average: ";
y = Average(T,size);
cout<<y<<endl;
outData<<y<<endl;
break;
case 'd': cout<<"Largest Number in Array: ";
outData<<"Largest Number in Array: ";
y = LargestNum(T,size);
cout<<y<<endl;
outData<<y<<endl;
break;
case 'e': cout<<"Smallest Number in Array: ";
outData<<"Smallest Number in Array: ";
y = SmallestNum(T,size);
cout<<y<<endl;
outData<<y<<endl;
break;
case 'f': cout<< "The number is at position(s): ";
outData<< "The number is at position(s): ";
y = Search(T,size);
cout<<y<<endl;
outData<<y<<endl;
break;
case 'g': cout<<"Numbers between: "<<
outData<<"Numbers between: ";
y = Between(T,size);
cout<<y<<endl;
outData<<y<<endl;
break;
case 'h': cout<<"Insertion of Number Array: "<<endl;
outData<<"Insertion of Number Array: "<<endl;
Insertion(T,size);
display_Array(T,size);
break;
case 'i': cout<<"New Array after Deleted Number: "<<endl;
outData<<"New Array after Deleted Number: "<<endl;
Delete(T,size);
display_Array(T,size);
break;
case 'z': cout<<"EXIT"<<endl;
die = 0;
break;
default:
cout<<"INVAILD ENTRY"<<endl;
outData<<"INVAILD ENTRY"<<endl;
break;
}
}
void Arwork :: Load(float T[100],int size)
{
char answ;
//prompts the user for keyboard of file input
cout<< "Would you like to input from File or Keyboard" << endl;
cout<< "Enter 'f' or 'k'" << endl;
cin>> answ;
//Keyborad input
if(answ == 'k')
{
cout<< "Enter all the data at once or (Ctrl-Z to quit)" << endl;
outData<< "Enter all the data at once or (Ctrl-Z to quit)" << endl;
int i =0;
while(cin)
{
cin >> T[i];
outData<< T[i]<< " ";
if(cin) i++;
size++;
}
size = size-1;
}
else
{
//file input
string fileName;
cin.clear();
cout<< "Input file name, then press Ctrl-D, Enter" << endl;
outData<< "Input file name, then press Ctrl-D, Enter" << endl;
cin >> fileName;
inData.open(fileName.c_str());
int i=0;
for (int i = 0; inData>> T[i]; i++)
++size;
size = size-1;
}
}
//sorts the array
void Arwork :: Sort(float T[100], int size)
{
int i, j, smallestAt;
for (int i = 0 ; i < size - 1 ; i++)
{
smallestAt = i;
for (j = i + 1 ; j < size ; j++)
{
if (T [j] < T[smallestAt])
{
smallestAt = j;
}
}
//calls swap
if (smallestAt != i)
{
swap (i, smallestAt, T);
}
}
sorted = true;
}
//swaps the numbers in the array
void Arwork :: swap (int loc1, int loc2,float T[])
{
float temp = T [loc1];
T [loc1] = T [loc2];
T [loc2] = temp;
}
//computes the average
float Arwork:: Average(float T[100], int size)
{
float total = 0.0;
for(int k = 0;k< size;k++)
{
total += T[k];
}
cout<<total/size<<endl;
outData<<total/size<<endl;
return total/size;
}
//finds the smallest number
float Arwork :: SmallestNum(float T[],int size)
{
float min = 0.0;
for(int k = 0;k< size;k++)
{
if(T[k]<min)
{
min = T[k];
}
}
cout<<min<<endl;
outData<<min<<endl;
return min;
}
//finds the largest integer
float Arwork :: LargestNum(float T[100], int size)
{
float max = 0.0;
for(int k = 0;k< size;k++)
{
if(T[k] > max)
{
max = T[k];
}
}
cout<<max<<endl;
outData<<max<<endl;
return max;
}
//inserts a number in an array
void Arwork :: Insertion(float T[100],int size)
{
float target = 0.0;
cout<<"Enter the number you are inserting"<<endl;
outData<<"Enter the number you are inserting"<<endl;
cin>>target;
int k=0;
while((k< size) && (T[k] < target))
k++;
for(int index = size -1; index>=k;index --)
{
T[index + 1] = T[index];
}
T[k] = target;
size = size + 1;
}
//deletes a number in an array
void Arwork :: Delete(float T[100],int size)
{
float target = 0;
cout<< "Enter the number you wish to delete" <<endl;
outData<<"Enter the number you wish to delete" <<endl;
cin>>target;
int k=0;
while((k<size) && (T[k] != target))
k++;
for(int index = k+1; index < size; index++)
T[index -1] = T[index];
size++;
}
//finds a number in an array
int Arwork :: Search(float T[100], int size)
{
int num;
if(sorted == true)
{
float target = 0;
cout<< "Enter the number you wish to search for:" <<endl;
outData<< "Enter the number you wish to search for:" <<endl;
cin>>target;
int k=0,h=0;
for(h=0;h<size;h++)
{
if(T[h] == target)
return h;
}
}
else
{
cout<<"ARRAY NEEDS TO BE SORTED FIRST"<<endl;
outData<<"ARRAY NEEDS TO BE SORTED FIRST"<<endl;
}
return 0;
}
//counts how many values are between two numbers
float Arwork :: Between(float T[100], int size)
{
int k = 0;
int j = 0;
float num1,num2;
cout<< "Enter your First Number then press Enter" <<endl;
outData<< "Enter your First Number then press Enter" <<endl;
cin>> num1;
cout<< "Enter your Second Number then press Enter" <<endl;
outData<< "Enter your Second Number then press Enter" <<endl;
cin>> num2;
for(k=0;k > size;k++)
{
if((T[k]>num1)&&(T[k]<num2))
cout<<T[k];
}
return j;
}
//displays the array
void Arwork :: display_Array(float T[100], int size)
{
int k =0;
for(k = 0;k<size;k++)
cout<<T[k]<<" ";
cout<< " "<<endl;
}
![]() |
Similar Threads
- [Namespace Error]Only sometimes run the GUI.. (C#)
- namespace error (C++)
- namespace std (C++)
- is not a class or namespace name error (C++)
- Debugging error C2653 (C++)
Other Threads in the C++ Forum
- Previous Thread: Problem with string search of an array
- Next Thread: In over my head
| Thread Tools | Search this Thread |
api array arrays based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion convert count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






