Answer to Question #234856 in C++ for upcoming legend

Question #234856
Surname Score
1. Sam Williams 60
2. John Phoenix 85
3. Simon Johnson 75
4. Sarah Khosa 81
5. Mat Jackson 38
6. Nick Roberts 26
7. Isaac Wayne 74
8. Anna Mishima 34
9. Daniel Rose 64
10. Aaron Black 83
11. Jack Mohamed 27
12. Kathrine Bruckner 42
Create a C++ program that has 3 Stacks.
Insert, into the first stack, all the data above (which is the data of student’s names,
surnames and the marks they obtain in a particular assessment)
Display the content of the stack on the screen (console)
Then, remove all the students whose surname starts with the alphabets ‘R’, ‘J’ and
‘M’, from the first stack and insert them into the second Stack.
Display the contents of Stack1 and Stack2.
Finally, remove all the students whose marks are less than 50 from both Stack1
and Stack2 and insert them into the Third Stack.
Display the contents of all the 3 Stacks. (30)
1
Expert's answer
2021-09-09T00:01:13-0400


#include <iostream>
#include <stack>
using namespace std;


int main()
{
    stack<string> s1;
    stack<string> s2;
    stack<string> s3;
    s1.push("Sam Williams 60");
    s1.push("John Phoenix 85");
    s1.push("Simon Johnson 75");
    s1.push("Sarah Khosa 81");
    s1.push("Mat Jackson 38");
    s1.push("Nick Roberts 26");
    s1.push("Isaac Wayne 74");
    s1.push("Anna Mishima 34");
    s1.push("Daniel Rose 64");
    s1.push("Aaron Black 83");
    s1.push("Jack Mohamed 27");
    s1.push("Kathrine Bruckner 42");
    while (!s1.empty()) {
        cout << ' ' << s1.top()<<endl;
        s1.pop();
    }
    while (!s1.empty()) {
        s2.push(s1.top());
        s1.pop();
    }
    while (!s1.empty()) {
        cout << ' ' << s2.top()<<endl;
        s2.pop();
    }
     while (!s2.empty()) {
        s3.push(s2.top());
        s2.pop();
    }
    while (!s1.empty()) {
        cout << ' ' << s3.top()<<endl;
        s3.pop();
    }
    
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS