Write c++ statements for each of the following: 1. Write the statements to input
ID: 3683281 • Letter: W
Question
Write c++ statements for each of the following:
1. Write the statements to input numeric exam scores from a file and output the appropriate letter grade.
2. Write code to print Arizona State University 10 times.
3. Write code to print the numbers from 10 to 1.
4. Write code that prints your name 5 times.
5. Write code that will request the length and width of a rectangle until 0 is entered for either the length or the width. Print the area and perimeter for each set of inputs.
6. What is the output for the following loop?
int number;
number = 1;
while (number < 11)
{
number = number + 1;
cout << number << endl;
}
7. What is the output of the following if the file contains: 2 3 4 5 6 7
int sum, num;
sum = 0;
infile >> num;
while (infile)
{
if (num % 2 == 0)
sum = sum + num;
infile >> num;
}
cout << sum << endl;
Explanation / Answer
1)
ans:
#include<string.h>
#include<iostream.h>
#include<fstream.h>
int main()
{
std::fstream myfile("D:\data.txt", std::ios_base::in);
float p;
while (myfile >> p)
{
if(p>=90 &&p<=100)
cout<<"A";
else if(p<90 && p>=80)
cout<<" B";
else if(p<80 && p>=70)
cout<<"C";
else if(p<70 && p>=60)
cout<<"D";
else
cout<<"F";
}
return 0;
}
2)ans:
for(int i=0;i<9;i++)
cout<<"Arizona State University";
3)ans:
for(int i=10;i>0;i--)
cout<<i;
4)ans:
for(int i=0;i<5;i++)
cout<<"XXXXXXXname";
5)ans:
int main()
{
int height,width;
cout<<"enter height and width";
cin>>height>>width;
while(height>0 && width>0)
{
cout<<"enter height and width";
cin>>height>>width;
cout<<"area"<<height*width;
cout<<"perimeter"<<2*(height+width);
cout<<"enter height and width";
cin>>height>>width;
}
}
6)ans:
output:2
3
4
5
6
7
8
9
10
11
7)ans:
output:12
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.