السلام عليكم ورحمة لله وبركاته
أهلا اخواني أخواتي بالمنتدى
تبعا لموضوعي بالأمس اللي
أول شي اعتذر لم أكن أعلم انه ممنوع الحلول
لكن حاولت في السؤال ويمكن قدرت فيه
حابة أشوف اذا فكرتي وحلي صحيح أو لا وياليت ألاقي منك مساعدة
وووووووووووووشكرا للجميع
#include<iostream>
#include<string>
using namespace std;
template <class T>
class Array {
private:
int size; // size of the array
T *ptr; // pointer to first element of array
int subscript; //location of element
public:
Array( int x = 10 ) // default constructor
{
size=x;
ptr=new T[x];
subscript=0;
}
~Array() // destructor
{
delete []ptr;
}
void AppendLast(const T element) // Add element at end of array
{
if(subscript<size)
ptr[subscript]=element;
subscript++;
}
void DeleteLast() // Delete last element
{
if(subscript>=0)
ptr[subscript]=0;
subscript--;
}
struct A{
string name;
double id;
int level;
};
int main()
{
Array<int>a(20);
A var;
a.AppendLast(var);
var.name="ola";
return 0;
}