Project 3 Static Stack Create an array of student records (at least 15) and put
ID: 3589099 • Letter: P
Question
Project 3 Static Stack Create an array of student records (at least 15) and put all the related student records information in an array like Project 1: Student Id, Name, Address and average of test scores and a Pointer for Test Scores (at least 10 scores) -Display the student records in the array (do not display pointers). -Push all student records from the array to a static stack. -Pop 5 student records from the stack and display the popped records. -Display the remaining student records in the static stack.Explanation / Answer
#include <iostream>
using namespace std;
struct student
{
int id;
string name;
string address;
float average;
int *pointTomarks[10];
};
class stack
{
student data[15];
int top;
public:
stack()
{
top=-1;
}
void push(student s);
void pop();
void display();
};
void stack::push(student s)
{
if(top==15-1)
{
cout<<" Stack is full";
return;
}
else
{
top++;
data[top] = s;
}
}
void stack::pop()
{
if(top==-1)
cout<<" Stack is empty";
else
{
cout<<data[top].id<<data[top].name<<data[top].address<<data[top].average<<endl;
top--;
}
}
void stack::display()
{
int t=top;
while(t>=0)
{
cout<<data[top].id<<data[top].name<<data[top].address<<data[top].average<<endl;
t--;
}
}
int main()
{
student st[15];
for(int i=0; i<15;i++){
cout<< "To create Enter id(int), name(string), address(string), average(float) of "<<i<<"th students"<<endl;
cin>>st[i].id>>st[i].name>>st[i].address>>st[i].average;
}
for(int i=0; i<1; i++){
cout<<st[i].id<<" "<<st[i].name<<" "<<st[i].address<<" "<<st[i].average<<endl;
}
stack ss;
for(int i=0; i<15; i++){
ss.push(st[i]);
}
for(int i=0; i<5; i++){
ss.pop();
}
ss.display();
return 0;
}
hope it may help you
thank you
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.