In the below code, i used the funtion push,pop and display(equivalent to Read_record).
the code is quite simple, i used comments in most of the portion, if you still found it difficult to understand, do comment the comment section, i'll reply ASAP.
#include<iostream>
#include<string.h>
using namespace std;
#define MAX 5 // maximum number of student record can be 5
// you can also make this field as user input
int TOP;
struct Student{
int Id;
char Name[100];
};
Student STACK[MAX];
//stack initialization
void initStack(){
TOP=-1;
}
//check it is empty or not
int isEmpty(){
if(TOP==-1)
return 1;
else
return 0;
}
//check stack is full or not
int isFull(){
if(TOP==MAX-1)
return 1;
else
return 0;
}
void push(int Id,char d[]){
if(isFull()){
cout<<"STACK is FULL."<<endl;
return;
}
++TOP;
STACK[TOP].Id=Id;
strcpy(STACK[TOP].Name,d);
cout<<Id<<" has been inserted."<<endl;
}
void display(){
int i;
if(isEmpty()){
cout<<"STACK is EMPTY.No student record
found"<<endl;
return;
}
for(i=TOP;i>=0;i--){
cout<<STACK[i].Id<<","<<STACK[i].Name<<endl;
}
cout<<endl;
}
//pop - to remove student record
void pop(){
int temp;
if(isEmpty()){
cout<<"STACK is EMPTY."<<endl;
return;
}
temp=STACK[TOP].Id;
TOP--;
cout<<temp<<" has been deleted."<<endl;
}
int main(){
int Id;
char Name[100];
initStack();
char ch;
do{
int a;
cout<<"Chosse
\n1.push\n"<<"2.pop\n"<<"3.display\n";
cout<<"Please enter your choice: ";
cin>>a;
switch(a)
{
case 1:
cout<<"Enter a ID of student: ";
cin>>Id;
cout<<"Enter Name of the student:";
cin>>Name;
push(Id,Name);
break;
case 2:
pop();
break;
case 3:
display();
break;
default :
cout<<"An Invalid Choice!!!\n";
}
cout<<"Do you want to continue ?y for Yes, n for No ";
cin>>ch;
}while(ch=='Y'||ch=='y');
return 0;
}
Write a C++ program to read N students records implementing stack using pointers. Each record has...
Need help. write a C program stack-ptr.c that implements a stack using a link list. Below is a skeleton code to start with.Jjust edit to make thread friendly. examplpe: push(5, &top); push(10, &top); push(15, &top); int value = pop(&top); value = pop(&top); value = pop(&top); this program currently has a race condition. use Pthread mutex locks to fix the race conditions. test you now thread safe stack by creating 200 concurrent threads in main() that push and pop values. -use...
==============C++ or java================Write a modularized, menu-driven program to read a file with unknown number of records.Create a class Records to store the following data: first and last name, GPA , an Id number, and an emailInput file has unknown number of records; one record per line in the following order: first and last names, GPA , an Id number, and emailAll fields in the input file are separated by a tab (‘\t’) or a blank space (up to you)No error...
Write a program that uses a stack to reverse its inputs. Your
stack must be generic and you must demonstrate that it accepts both
String and Integer types. Your stack must implement the following
methods:
push,
pop,
isEmpty (returns true if the stack is empty and false
otherwise), and
size (returns an integer value for the number of items in the
stack).
You may use either an ArrayList or a LinkedList to implement
your stack. Also, your pop method must...
C++ Please Write a function to copy one stack to another stack and leave the first stack unchanged. Only use the stack member functions: push pop top empty Your program should: create a stack prompt the user for a list of names and add them to the stack create a second stack call a function to copy the contents of the first stack to the second stack (leaving the first stack unchanged) empty the contents of the first stack (displaying...
Write a C++ program to store and update students' academic records in a binary search tree. Each record (node) in the binary search tree should contain the following information fields: 1) Student name - the key field (string); 2) Credits attempted (integer); 3) Credits earned (integer); 4) Grade point average - GPA (real). All student information is to be read from a text file. Each record in the file represents the grade information on...
Using c++ write a program using a class that has data members ID#,NAME, SALARY, YEAR_HIRED. This program must 1) write 10 blank records to a random access file. You must enter data for 4 of these records. 2) allow the user to output the name, salary, hire_date for a selected record 3) allow the user to change the name, salary, or hire_date for a selected record. 4) allow the user to input a complete record to replace one of the...
C or C++ I need to create a code with implementing stack using linked list(and should not use static array) and for input, each line should be this following order form: name, id, and email and for output, each line should be this order: id, name, and email here is examples of text files example1.txt Geo, 10, geoff@duke.edu Yoa, 13, yoshua@montreal.edu Yon, 19, yann@nyu.edu Cpo, 48, cho@nyu.edu Apx, 55, alex@amind.com example2.txt Joh, 50, jonnathan@hello.edu Jea, 20, jessicca@gmila.com Dav, 194, david@hi.edu...
Using either a Stack or Queue, write a C++ program that uses a for loop to push or enqueue 100 integers (values of 1-100) onto a stack or queue. Afterwards, the program should pop or dequeue these values off the stack or queue and write them to one of two textfiles (int.txt and int2.txt) based on whether a value is even or odd. If the popped or dequeued value is even, then that particular value should be written into int2.txt....
// Header code for stack // requesting to create source code using C++ #ifndef Stack_h #define Stack_h #include <stdio.h> #include <string> #include <iostream> using namespace std; class Stack { public: Stack(); ~Stack(); bool empty(); string top(); void push(const string &val); void pop(); void display(ostream &out); private: class Node { public: string word; Node *next; }; Node *tos; }; #endif Header file provided above. PLS create source code for functions declared in the header. If changes are need no make in...
Write a C program to compute average grades for a course. The course records are in a single file and are organized according to the following format: Each line contains a student’s first name, then one space, then the student’s last name, then one space, then some number of quiz scores that, if they exist, are separated by one space. Each student will have zero to ten scores, and each score is an integer not greater than 100. Your program...