Answer to Question #227455 in C++ for Sandile

Question #227455
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
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.
3b. Sort all the stacks in this order:
Stack1 in alphabetic order by name
Stack2 in alphabetic order by Surname
Stack3 in Numeric order (descending) by marks obtained.
1
Expert's answer
2021-08-20T14:17:10-0400
using namespace std;
#include <omp.h>
#include <stdio.h>
int main()
{
	string input[] = {"Sam Williams", "John Phoenix", "Simon Johnson", "Sarah Khosa", "Mat Jackon", "Nick Roberts", "Isaac Wayne", "Anna Mishima", "Daniel Rose", "Aaron Black", "Jack Mohamed", "Kathrine Bruckner"};
	int Score[] = {60, 85, 75, 81, 38, 26, 74, 34, 64, 83, 27, 42};   
	string s;
	string x;
	int a,l;
	l=sizeof(input)/sizeof(input[0]);
   	stack<string> Stack_1;
   	stack<int> ScoreStack_1;
   	stack<string> Stack_2;
   	stack<int> ScoreStack_2;
   	stack<string> Stack_3;
   	stack<int> ScoreStack_3;
   	
	for(int i=0;i<l;i++) {Stack_1.push(input[i]); ScoreStack_1.push(Score[i]);}
	   	
	cout<<"\nStack-1: "<<endl;
	for(int i=0;i<l;i++)
	{
		x = Stack_1.top(); 
        Stack_1.pop(); 
		a = ScoreStack_1.top(); 
        ScoreStack_1.pop(); 
		cout<<"\t"<<setw(20)<<x<<"\t"<<a<<endl;
	}
	
	string space_delimiter = " ";
	for(int i=0;i<l;i++)
	{
		x = input[i];
    	string word = "";
    	for (int j=0;j<x.length() ; j++)
    	{
    		char u=x[j];
        	if (u == ' ')     	word = "";			//First Name
        	else 		        word = word + u;	//Sur Name
    	}
//    	cout << word << "\t"<<word[0]<<endl;	
    	if(word[0]!='R'&&word[0]!='J'&&word[0]!='M') {Stack_2.push(input[i]); ScoreStack_2.push(Score[i]);}
	}


   	cout<<"\nStack-3";
	for(int i=0;i<l;i++)
	{
		int n = Score[i];
		if(n>50) 
		{
			Stack_3.push(input[i]); ScoreStack_3.push(Score[i]);	
			cout<<"\t"<<setw(20)<<input[i]<<"\t"<<n<<endl;
		}
		
	}
	
	cout<<"\n\nStack-2: "<<endl;
	for(int i=0;i<l;i++)
	{
		x = Stack_2.top(); 
        Stack_2.pop(); 
		a = ScoreStack_2.top(); 
        ScoreStack_2.pop(); 
		cout<<"\t"<<setw(20)<<x<<"\t"<<a<<endl;
	}
   
   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