Please help me Write a C ++ program that computes a student\'s grade for an assi
ID: 3929499 • Letter: P
Question
Please help me Write a C ++ program that computes a student's grade for an assignment as a percentage given the student's score and the total points The final score should be rounded up to the nearest whole value using the ceil function in the header file. You should 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 a space. Write an interactive C++ program that inputs a name from the user in the following format: last, first middle The program should then output the name in the following format: first middle last The program will have to use string operation to remove the comma from the end of the last name. Be sure to use proper formatting and appropriate comments in your code. The input should have an appropriate prompt, and the output should be labeled clearly and formatted neatly. Write an interactive C ++ program whose input it a series of 12 temperatures from the user. It should write out on file tempdata.dat each temperature as well as the difference between the current temperature and the one preceding it. The difference is not output for the first temperature that is input. At the end of the program, the average temperature should be displayed for the user via cout. For example, given the input data 34.5 38.6 42.4 46.8 51.3 63.1 60.2 55.9 60.3 56.7 50.3 42.2 file temdata.dat would contain Be sure to use proper formatting and appropriate comments in your code. The input should be collected through appropriate prompts, and the output should be labeled clearly and formatted neatly.Explanation / Answer
Solution for Question 1:
#include<iostream>
#include<fstream>
#include<string>
#include<cmath>
using namespace std;
int main()
{
ifstream file("filename.txt"); // opening the file with the default filename
string s;
int score,total=0;
float percentage;
if(file.is_open())
{
while(getline(file,s)) // getting the first and reading into String s
{
istringstream iss(s); // reading each element in the string as integer
}
file.close();
while(iss >> score)
{
total+=score; // Adding the values read from the file
}
score=total-score; // getting score out of the numbers read from file Ex : 800+1000 = 1800 and score will be //1800-1000 = 800
percentage = (float)(score/total); // converting the division into float
percentage*=100;
setprecision(5); //setting decimal precision to 5 points
cout << "Score with decimals " << percentage << endl;
}
else
cout << "Unable to open the file" << endl;
return 0;
}
Solution for Question 2:
#include<iostream>
#include<string>
using namespace std;
int main()
{
string name,firstname,midname,lastname;
cout << "Enter the name : " << " " <<endl;
getline(cin,name); // taking input as the string
int n=name.length(); // taking full string length of the input
lastname=getlastName(name); //calling method to get the last name
int n1=lastname.length(); // Storing the length of lastname in n1.
firstname=getfirstName(name);
int n2 = firstname.length(); // getting length of firstname
n2=n1+n2;
midname=getMidName(name); // storing Mid name in midname variable
cout <<firstname <<" "<< midname << " " << lastname<< endl; // :Printing output as expected
return 0;
}
string getlastName(string name)
{
string str=null;
for(int i=0;i<n;i++)
{
if(name[i]!=',')
{
str[i]=name[i];
}
else
break;
return str; // returning the last name
}
}
string getfirstName(string name)
{
string str; int k;
for(int i=0;i<n;i++)
{
if(i<=n1)
continue;
else if(name[i]!=' ')
{
str[i]=name[i];
}
else if(name[i]==' ')
break;
return str; // return firstname
}
}
string getMidName(string name)
{
string str;
for(int i=0;i<n;i++)
{
if(i<=n2)
continue;
else
{
str[i]=name[i]; // storing the string of midname in str.
}
return str;
}
Solution for Question 3:
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
cout << "Enter the input temperatures : " << endl;
int n1=12; //taking 12 as series of temp
float n[12]; //storing them in an array
float j,Avg=0,diff;
ofstream file; // file initialization
file.open("tempdata.dat"); // opening file to write the output
for(int i=0;i<n1;i++)
{
cin>>j;
n[i]=j; //Storing elements
Avg+=j;
if(i>0)
{
diff=n[i]-n[i-1];
file << n[i] << " " << diff << " ";
}
else
file << n[i] << " "; // Writing only temperature value for the first input
}
Avg = Avg/n1;
file << "Average of the values is " << Avg << endl; // Writing Average Value to the file at the end
file.close();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.