C++ CS : if
die's job is to output an error message alarmingly and terminate the program. You may copy my
function definition, or use your own:
// The following 4 lines should be present if we have a die function:
#include <iostream> // cout, endl
#include <string> // string
#include <cstdlib> // exit, EXIT_FAILURE
using namespace std;
bool die(const string & msg){
cout <<"Fatal error: " <<msg <<endl;
exit(EXIT_FAILURE);
}
1. Tier
Prompt the user, then input the student's first name (one word only) and score (fixed point, in the
range [0, 100]).
If the input fails, c&d (complain and die by calling the die function).
If the score is out of range, c&d.
This program's job is to determine and output the student's grade: A, B, C, D, or F.
This is according to the score:
[85, 100]: A
[73, 85): B
[61, 73): C
[49, 61): D
[0, 49): F
EXCEPT that if the student's name is my name ("Bob") or your name, and the student earned less
than A, then the student's grade is promoted to the next better grade.
A run of your program might go as:
name score:
John 84
John gets B
(John earned B and got B)
Another run of your program might go as:
name score:
Bob 84
Bob gets A
(Bob earned B but got A)
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin >> s;
stack<int> st;
int ans=0,cur=-1,thi=-1,count=0;
string sign;
for(int i=0;i<s.size();i++){
if(s[i]-'0'>=0 && s[i]-'0'<=9){
st.push(s[i]-'0');
}
else{
int base=1;
thi=0;
while(st.size()!=0){
int temp=st.top();
thi+=(temp*base);
st.pop();
base*=10;
}
if(count==0){
ans=thi;
}
else{
if(thi==0 && (sign[0]=='/' || sign[0]=='%')){
cout<<"Error "<<endl;
return 0;
}
if(sign[0]=='+'){
ans+=thi;
}
if(sign[0]=='-'){
ans-=thi;
}
if(sign[0]=='*'){
ans*=thi;
}
if(sign[0]=='/'){
ans/=thi;
}
if(sign[0]=='%'){
ans%=thi;
}
}
count++;
sign=s[i];
}
}
if(st.size()==0){
cout<<"Invalid expression"<<endl;
}
else{
int base=1;
thi=0;
while(st.size()!=0){
int temp=st.top();
thi+=(temp*base);
st.pop();
base*=10;
}
if(thi==0 && (sign[0]=='/' || sign[0]=='%')){
cout<<"Error "<<endl;
return 0;
}
if(sign[0]=='+'){
ans+=thi;
}
if(sign[0]=='-'){
ans-=thi;
}
if(sign[0]=='*'){
ans*=thi;
}
if(sign[0]=='/'){
ans/=thi;
}
if(sign[0]=='%'){
ans%=thi;
}
cout<<ans<<endl;
}
return 0;
}
COMMENT DOWN FOR ANY QUERY
PLEASE GIVE A THUMBS UP
C++ CS : if die's job is to output an error message alarmingly and terminate the...
C++ 1: Grade Prompt the user for name (first name only, only one word) and score (which will be input as a fixed point number). Input the values, c&d on input failure. The score should be in the range [0, 100], otherwise c&d. Compute the grade and output with explanatory text. The grade for most students according to [85, 100]: A [73, 85): B [61, 73): C [49, 61): D [0, 49): F (Note that in the above I use...
Can someone help me put the string removee the return to an outfile and fix?? prompt: CS 575 LabEx14: no e’s Let the user specify an input file and an output file (text files). Read the input file and write the output file; the output file should be the same as the input file, except that it has no e’s. For example, if the input file had the line. Streets meet in the deep. Then the output file would have...
4-card poker Prompt the user, input 4 fixed point values, which can be input in any order. C&d on input failure. Each of the 4 numbers is supposed to be in the range [1, 13], otherwise c&d. Output the appropriate one of the following 5 messages: 4 of a kind 3 of a kind two pairs one pair nothing For example, if the input were 5 5 1 5 then your program would output 3 of a kind I don't...
Am I getting this error because i declared 'n' as an int, and then asking it to make it a double? This is the coude: #include "stdafx.h" #include <iostream> #include <fstream> #include <string> #include <algorithm> #include <vector> using namespace std; void sort(double grades[], int size); char calGrade(double); int main() { int n; double avg, sum = 0;; string in_file, out_file; cout << "Please enter the name of the input file: "; cin >> in_file; ...
Microsoft Visual Studios 2017 Write a C++ program that computes a student’s grade for an assignment as a percentage given the student’s score and total points. The final score must be rounded up to the nearest whole value using the ceil function in the <cmath> header file. You must also display the floating-point result up to 5 decimal places. The input to the program must come from a file containing a single line with the score and total separated by...
C++ Redo PROG8, a previous program using functions and/or arrays. Complete as many levels as you can. Level 1: (20 points) Write FUNCTIONS for each of the following: a) Validate #students, #scores. b) Compute letter grade based on average. c) Display student letter grade. d) Display course average. Level 2: (15 points) Use ARRAYS for each of the following. e) Read a student's scores into array. f) Calculate the student's average based on scores in array. g) Display the student's...
please help me fix the error in here #include<iostream> #include <string> using namespace std; string getStudentName(); double getNumberExams(); double getScoresAndCalculateTotal(double E); double calculateAverage(double n, double t); char determineLetterGrade(); void displayAverageGrade(); int main() { string StudentName; double NumberExam, Average, ScoresAndCalculateTotal; char LetterGrade; StudentName = getStudentName(); NumberExam = getNumberExams(); ScoresAndCalculateTotal= getScoresAndCalculateTotal(NumberExam); Average = calculateAverage(NumberExam, ScoresAndCalculateTotal); return 0; } string getStudentName() { string StudentName; cout << "\n\nEnter Student Name:"; getline(cin, StudentName); return StudentName; } double getNumberExams() { double NumberExam; cout << "\n\n Enter...
I have a C++ code that lets me enter, display and delete a
student record. I need to implement a function that prints the
average grade score of the students I input.
Below is my code and a picture of how my code looks right
now.
#include<iostream>
#include<stdlib.h>
using namespace std;
//Node Declaration
struct node
{
string name;
string id;
int score;
node *next;
};
//List class
class list
{
private:
//head...
Need help with a C++ program. I have been getting the error "this function or variable may be unsafe" as well as one that says I must "return a value" any help we be greatly appreciated. I have been working on this project for about 2 hours. #include <iostream> #include <string> using namespace std; int average(int a[]) { // average function , declaring variable int i; char str[40]; float avg = 0; // iterating in...
i need this written in C, not C++ or anything else, just C,
thank you.
apparently this works, but I can't use this, hope this helps
though:
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
char finalist1[10], finalist2[10], winner[10];
char decision[3][10];
int count1=0,count2=0,i;
cout<<"Enter name of the first finalist: ";
gets(finalist1);
cout<<"\nEnter name of the second finalist: ";
gets(finalist2);
cout<<"\n\nEnter decision of the first committee member:
";
gets(decision[0]);
if(strcmp(decision[0],finalist1)==0 ||
strcmp(decision[0],finalist2)==0)
{
cout<<"\nEnter decision of the second committee member:
";...