#include"ArrayList.h"
#include<iostream>
usingnamespace std;
template<class T>
void func(ArrayList<T>&object) {
int opt = 0;
while (opt != 7) {
cout << "1 to add element" << endl;
cout << "2 add element + index" << endl;
cout << "3 minmun value" << endl;
cout << " 4 Maximun value" << endl;
cout << "5 array size" << endl;
cout << "print array values" << endl;
cout << "exit" << endl;
cin >> opt
if (opt == 1) {
T value = 0;
bool input = false;
while (!input) {
cout << "ADD value " << endl;
if (cin >> value) {
object.addElement(value);
input = true;
}
else {
cout << "wrong input" << endl;
input = false;
}
cin.clear();
cin.ignore(INT_MAX, '\n');
}
}
elseif (opt == 2) {
cout << "ADD value and index" << endl;
int index = 0;
T value;
char c;
bool flag = false;
while (!flag) {
cout << "Add value" << endl;
if (cin >> value >> c >> index && index >= 0 && index <= object.getSize()) {
object.addElement(value, index);
flag = true;
}
else {
cout << "wrong input" << endl;
flag = false;
cin.clear();
cin.ignore(INT_MAX, '\n');
}
}
}
elseif (opt == 3) {
if (object.getSize() > 0) {
cout << object.popMin() << endl;
}
else {
cout << "cant find any value in the Array" << endl;
}
}
elseif (opt == 4) {
if (object.getSize() > 0) {
cout << object.popMax() << endl;
}
else {
cout << "cant find any value in the Array" << endl;
}
}
elseif (opt == 5) {
cout << object.getSize() << endl;
cin.clear();
cin.ignore(INT_MAX, '\n');
}
elseif (opt == 6) {
object.print();
cin.clear();
cin.ignore(INT_MAX, '\n');
}
elseif (opt == 7) {
cout << "Exit" << endl;
cin.clear();
cin.ignore(INT_MAX, '\n');
break;
}
else {
opt = 0;
cin.clear();
cin.ignore(INT_MAX, '\n');
}
}//end while
}
int main() {
int option = 0;
while (option != 3) {
cout << "1- for integers Array" << endl;
cout << "2-for char Array" << endl;
cout << "3 to exit program" << endl;
cin >> option;
if (option == 1) {
ArrayList<int>intArrayList;
func(intArrayList);
break;
}
elseif (option == 2) {
ArrayList<char>charArrayList;
func(charArrayList);
break;
}
elseif (option == 3) {
cout << "Exit program" << endl;
break;
}
else {
cout << "Not an option" << endl;
option = 0;
cin.clear();
cin.ignore(INT_MAX, '\n');
}
}
return 0;
}
header file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#pragma once
template<class T>
class ArrayList {
private:
T* storage;
int size;
public:
ArrayList(); //deafult constractor
ArrayList(const ArrayList& copy); //copy constractor
~ArrayList(); //destractor
void addElement(T toAdd); //add new value to the array at the end of the array
void addElement(T toAdd, int index); //add new value to the current idex
T popMin(); //return the min value
T popMax(); //return max value
int getSize()const; //return size of array
void print()const; //print array values
};
for almsot 6 hours trying to understand why this program not running ..
visual says: the system canot find file spesifect
can you try to run it? did it run? what should i do?
First of all its a bad habit to post the entire code you have and just ask "why is it not running".
The best place to start is to give us a proper error message.
start over. Build a new project in your tool and bring the code into it, see if you can get the message to clear up. It sounds a little like a corrupted project file, but you didn't give us much to go on. (You don't have to change any code for this, its an attempt to see if you have a tool error only -- you can save what you have).
i try to do the projet again keep getting error
moved all the template function to the header file still problem
even delete visual studio and install again same problem.
..
its says unable to start project ...
and says the system cannot find the file specified .
(popup error)
> UNABLE TO START project
> the system cant find the file specifect
post the full error message, just copy-paste it so there won't be typos.
also, ¿when does this happen?