Create an output format statement which would generate lines in the table which
ID: 3570827 • Letter: C
Question
Create an output format statement which would generate lines in the table which appear as shown below. The Element Name Field displays an element name contained in the name variable. YYY displays an integer value from the anum variable which ranges from 1 thru 109 and should be left justified. XXX.XXXX displays an atomic weight value from the aweight variable which ranges from 1.0000 to 268.0000 and should be right justified. Use the variables shown below in your output statements.
Element Name Field..YYY....XXX.XXXX
char name[15]; int anum; double aweight;
Explanation / Answer
#include <string>
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
char ele1[15] = "oxygen" ;
char ele2[15] = "hydrogen";
char ele3[15] = "potassium";
int y1 = 2;
int y2 = 34;
int y3 = 100;
double x1 = 1.0010;
double x2 = 22.12;
double x3 = 201.3126568;
printf("%-15s..%-3d....%3.4f ",ele1,y1,x1);
printf("%-15s..%-3d....%3.4f ",ele2,y2,x2);
printf("%-15s..%-3d....%3.4f ",ele3,y3,x3);
system("pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.