الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

سؤال في الclass اتمنى الرد بسرعه

مغلق
بدأه sofya في 9 أكتوبر 2004 · 3 رد · 450 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلااااااام عليكم ورحمة الله وبركاته

اللللللللله يعافيكم اتمنى انكم تصححون لي هالسؤال لاني حاولت فيه وحليته بس ياليت تقولون لي عن الاخطاء اللي فيه البرمجيه وليست الاقواس اللتي لم اضعها

ابي تقولون لي عن طريقة كتابة الكود الصحيح ماذا افعل؟؟

هذا هو السؤال ومحاولاتي كملف مرفق:

Develop a sequence class that holds a sequence of items of type string

The sequence is represented by an array of strings, in addition to the number of items currently in the sequence.

Provide the following methods

1. A constructor that creates an empty sequence

2. A Boolean function full that will test if the sequence cannot store any more item.

3. A function size that will return the current number of items in the sequence.

4. A function Append that will append a given string at the end of the sequence.

5. A function this_string that will return a reference to the item at a given position k.

6. A destructor function that will free the allocated memory .

Create a main function to test your sequence class.

1. Read in words one per line until a sentinel is reached.

2. Replace first letter of each word with capital letter . ex : replace a with A .

3. Print the sequence and its size.

sh.cpp

#2

للرفع ,,

لمن يعرف الحل ,,

banner_60_468.gif

NOTHING IS IMPOSSIBLE

#3
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <string >
using namespace std;

class sequence
{
	int s1;
	int count;
	char** seq;
public:
	sequence();//constructer
	~sequence();//destructer
	bool full();
	int size();
	void append(char st[]);
	char* this_string(int k);
};
sequence::sequence()
{
	cout<<"enter the number of size the array and the size in each elementn:\n";
	cin>>s1;
	seq=new char*[s1];
	count =0;
}
sequence::~sequence()
{
     cout << "freeing array\n";
        for(int i=0;i<s1;i++)
        delete []seq;
        delete []seq;
  
}
bool sequence::full()
{

	if (count==s1) 
  return true;
  else 
  return false;
}
int sequence::size()
{
	return count;
}
void sequence::append(char st[])
{
	if (full())
  cout << "connot appended\n";
	else
	{
  int len = strlen(st);
  seq[count] = new char[len];
  strcpy(seq[count],st);
  count++;
	}
}
char* sequence::this_string(int k)
{

 	 return seq[k];
}

int main()
{
	int s3;
	char temp[80];
	sequence s;

	cout<<"enter the words and 0 to stop\n";
	cin>>temp;
	while (temp[0] != '0')
	{ 
  s.append(temp);
  cin>>temp;
	}

  return 0;
}
#4

مشكووووووورين عالاجابه وجزاكم الله الف خير

هذا الموضوع مغلق.

مواضيع مشابهة