اخواني اتمنى الرد في اقرب وقت ،، عندي سؤال وحليته بس النواتج مب صحيحة ،، اذا تسمحوا مساعدتي في اعطائي نتيجة صحيحة ،،
هذا السؤال مع الكود
Write a program in C++ to do the following. create a stack of strings of size 10.
create a queue of strings of size 10.
(i) insert 10 students' names.
(ii) print the size of the queue.
(iii) delete the names from the queue. if the deleted name starts with the letter 'a' or 'A' then push the name into the stack of strings. repeat action (iii) until the queue becomes empty.
(iv) print the size of the stack.
(v) print all the names from the stack with the usual stack operations.
كود الحل
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<stdlib.h>
#include<cstdlib>
using namespace std;
int main()
{
string s[10];
stack<string> ss;
queue<string> stq;
int count=0;
cout<<"Enter 10 students Name:"<< endl;
for(int i=0; i<10; i++)
{
cin>>s;
stq.push(s);
count++;
}
cout<<"The size of the queue="<<stq.size()<<endl;
int count2=0;
while(!stq.empty())
{
string x=stq.front();
//if(x=="a" || x=="A")
if(x.substr(1)=="a" || x.substr(1)=="A")
ss.push(x);
stq.pop();
}
cout<<"The size of the stack: "<< ss.size()<<endl;
cout<<"The Names in the stack: "<<endl;
while(!ss.empty())
{
cout<<endl<<ss.top();
ss.pop();
}
while(!stq.empty())
{
stq.front();
stq.pop();
}
cout<<endl<<"The size of the queue: "<<stq.size();
return 0;
}السلام عليكم

