may i ask for help with this c++ problem?

this is the code i have for assignment 4 question 2:
#include<iostream>
#include<string>
#include<sstream>
#include<stack>
using namespace std;
int main()
{
string inputStr;
stack <int> numberStack;
cout<<"Enter your expression::";
getline(cin,inputStr);
int len=inputStr.length();
stringstream inputStream(inputStr);
string word;
int val,num1,num2;
while (inputStream >> word)
{
//cout << word << endl;
if(word[0] != '+'&& word[0] != '-' && word[0] != '*')
{
val=stoi(word);
numberStack.push(val);
// cout<<"Val:"<<val<<endl;
}
else if(word[0]=='+')
{
num1=numberStack.top();
numberStack.pop();
num2=numberStack.top();
numberStack.pop();
// cout<<num1<<" "<<word<<" "<<num2<<"="<<num1+num2<<endl;
numberStack.push(num1+num2);
}
else if(word[0]=='-')
{
num1=numberStack.top();
numberStack.pop();
num2=numberStack.top();
numberStack.pop();
// cout<<num1<<" "<<word<<" "<<num2<<"="<<num1-num2<<endl;
numberStack.push(num1-num2);
}
else if(word[0]=='*')
{
num1=numberStack.top();
numberStack.pop();
num2=numberStack.top();
numberStack.pop();
// cout<<num1<<" "<<word<<" "<<num2<<"="<<num1*num2<<endl;
numberStack.push(num1*num2);
}
}
int result=numberStack.top();
numberStack.pop();
if(!numberStack.empty())
{
cout<<inputStr<<" is invalid expression."<<endl;
}
else
{
cout<<"Result of RPN::"+inputStr<<" is "<<result<<endl;
}
return 0;
}
#include <iostream>
using namespace std;
//function to find First index of given number
int find(int a[],int n,int num)
{
int static i=0;
if(i==n)
return n;
if(a[i]==num)
return i;
i++;
return find(a,n,num);
}
//function to find last index of given number
int rfind(int a[],int n,int num)
{
int static i=n-1;
if(i<0)
return n;
if(a[i]==num)
return i;
i--;
return rfind(a,n,num);
}
int main( )
{
int length;
cout<<"Enter Array Length:";
cin>>length;//length of array
cout<<"\n";
//cout<<length;
if(length==0)
return 0;
else
{
int a[length];//array declaration
cout<<"Enter elements in an array\n";
//taking array input from user
for(int i=0;i<length;i++)
{
cin>>a[i];
}
cout<<"Enter element to be searched :";
int search;
cin>>search;//taking input of search
element
cout<<"\n";
cout<<"\nFirst Index of search element:(Index
starts from zero)";
cout<<find(a,length,search);//calling find()
functin on search element
cout<<"\n";
cout<<"\nLast Index of search element:(index
starts from zero)";
cout<<rfind(a,length,search);//calling rfind()
function on search element
}
}
May i ask for help with this c++ problem? this is the code i have for assignment 4 question 2: #...
C++ problem where should I do overflow part? in this code do not write a new code for me please /////////////////// // this program read two number from the user // and display the sum of the number #include <iostream> #include <string> using namespace std; const int MAX_DIGITS = 10; //10 digits void input_number(char num[MAX_DIGITS]); void output_number(char num[MAX_DIGITS]); void add(char num1[MAX_DIGITS], char num2[MAX_DIGITS], char result[MAX_DIGITS], int &base); int main() { // declare the array = {'0'} char num1[MAX_DIGITS] ={'0'}; char...
C++ I am using visual studio for it. Make a copy of the Rational class you created in the previous Lab. Modify the class. Replace all your mathematical, input, and output functions with overloaded operators. Overload the following 12 operators: + - * / < > = = ! = <= >= >> << In order to test your class in your main function, prompt the user for a numerator and a denominator for your first object. Repeat the prompt...
C++ Please ensure code is fully working, will rate Question to be answered: Repeat Exercise 1 for the class linkedStackType question one: Two stacks of the same type are the same if they have the same number of elements and their elements at the corresponding positions are the same. Overload the relational operator == for the class stackType that returns true if two stacks of the same type are the same, false otherwise. Also, write the definition...
NEED ASAP PLEASE HELP
Task:
---------------------------------------------------------------------------------------------------------------------------------
Tasks to complete:
----------------------------------------------------------------------------------------------------------------------------------------
given code:
-----------------------------------------------------------------------------------------------------------------------------------------------
main.cpp
#include <iostream>
#include <iomanip>
#include "fractionType.h"
using namespace std;
int main()
{
fractionType num1(5, 6);
fractionType num2;
fractionType num3;
cout << fixed;
cout << showpoint;
cout << setprecision(2);
cout << "Num1 = " << num1 << endl;
cout << "Num2 = " << num2 << endl;
cout << "Enter the fraction in the form a / b: ";
cin >> num2;
cout << endl;
cout <<...
(a) Write a recursive function int find(const int A[], int n, int x); which returns the first index i = 0, . . . , n − 1 such that A[i] == x, or n if it is not found. (b) Write a recursive function int rfind(const int A[], int n, int x); which returns the last index i = 0, . . . , n − 1 such that A[i] == x, or n if it is not found....
This is a fill in the code type: // FILL IN THE CODE - Write a program to multiply 2 numbers, print out the results and print out the original numbers in ascending order. #include <iostream> using namespace std; int main() { int num1; // holds 1st number int num2; // holds 2nd number int result; // holds result of multiplication int *num1Ptr = nullptr; // int pointer which will be set to point to the 1st number int *num2Ptr...
So the assignment is to write a program that have the user entered 3 numbers and than it will sort it by ascending order. Here are the code I wrote, but it won't compiled and I kept on getting an error message "Using uninitiazed memory" for all the variables. Can someone please help take a look and see whats going on? #include <iostream> using namespace std; int main() { //variables int num1, num2, num3; int lowest, middle, highest; //user inputs...
HI USING C++ CAN YOU PLEASE PROGRAM THIS ASSIGNMENT AND ADD
COMMENTS:
stackARRAY:
#include<iostream>
#define SIZE 100
#define NO_ELEMENT -999999
using namespace std;
class Stack {
int arr[SIZE]; // array to store Stack elements
int top;
public:
Stack() {
top = -1;
}
void push(int); // push an element into Stack
int pop(); // pop the top element from Stack
int topElement(); // get the top element
void display(); // display Stack elements from top to bottom
};
void Stack...
I need this done in C++ Can someone help me get my code from crashing. The code compiles but it can be easily crashed with user input. The rubric and code below Instructions: Write a program that scores the following data about a soccer player in a structure: Player’s Name Player’s Number Points Scored by Player The program should keep an array of 12 of these structures. Each element is for a different player on a...
I have C++ code. How I can change to Java code #include <iostream> using namespace std; int initialNumber[4]; int main() { void ShowResult(); //initialization int NuberOfpage[20]={1,0,7,1,0,2,1,2,3,0,3,2,4,0,3,0,2,1,0,7},i,j,f12[3]; int num1=0,num2=0,countr=0,framsize=3; int inital,current,current1; for(i=0;i<3;i++) { initialNumber[i]=-1; } for(j=0;j<20;j++) { num1=0,num2=0; for(i=0;i<3;i++) { if(initialNumber[i]==NuberOfpage[j]) { num1=1; num2=1; break; } } if(num1==0) { for(i=0;i<3;i++) { if(initialNumber[i]==-1) { initialNumber[i]=NuberOfpage[j]; num2=1; break; } } } if(num2==0) ...