make a visual basic program #include \"stdafx.h\" #include <iostream> #include <
ID: 3698617 • Letter: M
Question
make a visual basic program
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std
Explanation / Answer
Solution:
code:
#include<iostream> //Header files
#include<stdlib.h>
#include<iomanip>
#include<fstream>
//Namespace declaration
using namespace std;
//Starting of main function
int main()
{
//setting the precision to 2 decimal points
cout<<fixed<<setprecision(2)<<endl;
//Varibale data type declaration
string name;
double test1, test2;
float max, min, total_avg=0,Avg;
float N_Grades;
char L_Grade;
float Grades[100];
float TOTAL[100];
int i=0;
float total;
int count;
ifstream infile;
//open input.txt file for reading
infile.open("Grades.txt");
//error checking
if(!infile)
{
cout<<"Error in reading the file. ";
exit(0);
}
//setting the header
cout<<endl;
cout<<"STUDENT STATICS: "<<endl;
cout<<endl;
cout<<setw(20)<<left<<"Name"<<setw(20)<<left<<"Total Points"<<setw(20)<<left<<"Numeric Grade"<<setw(20)<<left<<"Letter Grade"<<endl;
cout<<endl;
//reading the data from the file
while(infile>>name>>test1>>test2)
{
//calculating total of tests
total = test1+test2;
//Calculating grades
N_Grades = total/2;
//Assigning Grades to a array to find min and max of the garades
Grades[i] = N_Grades;
//condtion checking and assign the grade according to the match found..
if(N_Grades>=90 && N_Grades<=100)
{
L_Grade = 'A';
}
else if(N_Grades>=80 && N_Grades<=90)
{
L_Grade = 'B';
}
else if(N_Grades>=70 && N_Grades<=80)
{
L_Grade = 'C';
}
else if(N_Grades>=60 && N_Grades<=70)
{
L_Grade = 'D';
}
else
{
L_Grade = 'F';
}
//Display Information
cout<<setw(20)<<left<<name<<setw(20)<<left<<total<<setw(20)<<left<<N_Grades<<setw(20)<<left<<L_Grade<<endl;
i++;
}
cout<<endl;
min = Grades[0];
max = Grades[0];
for(count=0;count < i; count++)
{
//Calculating total of grades
total_avg = total_avg + Grades[count];
//Calculating Avg of grades
Avg = total_avg/i;
}
//Finding min grade
for(count=0;count<i;count++)
{
if(Grades[count]<min)
{
min = Grades[count];
}
}
//finding max grade
for(count=0;count<i;count++)
{
if(Grades[count]>max)
{
max = Grades[count];
}
}
//Display Information
cout<<"CLASS STATICS:"<<endl;
cout<<endl;
cout<<"Number: "<<setw(10)<<right<<i<<endl;
cout<<"Minimum: "<<setw(10)<<right<<min<<endl;
cout<<"Maximum: "<<setw(10)<<right<<max<<endl;
cout<<"Average: "<<setw(10)<<right<<Avg<<endl;
//close files
infile.close();
return 0;
}
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.