Answer to Question #239007 in C++ for Owen

Question #239007

Name 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.


1
Expert's answer
2021-09-18T17:28:47-0400
#include <iostream>
#include <stack>
using namespace std;
class Student{
    public:
    string N, S;
    int M;
    Student(){
	
	}
    Student(string N, string S, int M){
        this->N = N;
        this->S = S;
        this->M = M;
    }
    void show(){
        cout<<"Name: "<<this->N<<endl;
        cout<<"Surname: "<<this->S<<endl;
        cout<<"Marks: "<<this->M<<endl<<endl;
    }
};
int main(){
    stack<Student> St3, St2, St1;
    St1.push(Student("Sam", "Williams", 60));
    St1.push(Student("John", "Phoenix", 85));
    St1.push(Student("Simon", "Johnson", 75));
    St1.push(Student("Sarah", "Khosa", 81));
    St1.push(Student("Mat", "Jackson", 38));
    St1.push(Student("Nick", "Roberts", 26));
    St1.push(Student("Isaac", "Wayne", 74));
    St1.push(Student("Anna", "Mishima", 34));
    St1.push(Student("Daniel", "Rose", 64));
    St1.push(Student("Aaron", "Black", 83));
    St1.push(Student("Jack", "Mohamed", 27));
    St1.push(Student("Kathrine", "Bruckner", 42));


    Student S1;
    cout<<"Displaying contents of Stack 3\n";
    while(!St1.empty()){
        S1 = St1.top();
        S1 .show();
        St3.push(S1 );
        St1.pop();
    }
    while(!St3.empty()){
        St1.push(St3.top());
        St3.pop();
    }
    while(!St1.empty()){
        S1  = St1.top();
        if(S1.S[0] == 'R' || S1.S[0] == 'J' || S1.S[0] == 'M'){
            St2.push(S1);
        }
        St3.push(S1);
        St1.pop();
    }
    cout<<"Displaying contents of Stack 2\n";
    while(!St2.empty()){
        S1 = St2.top();
        S1.show();
        St2.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