Need help in C++ programming 1. Create a program in C++ that includes two differ
ID: 3793652 • Letter: N
Question
Need help in C++ programming
1. Create a program in C++ that includes two different enumeration types and has a number of operations using the enumeration types. Also create the same program using only integer variables. Compare the readability and predict the reliability differences between the two programs.
2. Write a program in C++ to determine the scope of a variable declared in a “for statement”. Specifically, the code must determine whether such a variable is visible after the body of the “for statement”. Explain if the variable was or was not visible and why.
Explanation / Answer
2) #include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
for(int i=0;i<10;i++)// i declared inside the for loop this variable scope is block scope outside the this block i value // not there.i is not accessable outside of the for loop.when we access it doesn't compile // also.because i declared inside the block so it is treated as local variable local variable life time // is within the block only.
{
cout<<"the i value is "<<i<<endl;
}
}
output
the i value is 0
the i value is 1
the i value is 2
the i value is 3
the i value is 4
the i value is 5
the i value is 6
the i value is 7
the i value is 8
the i value is 9
1)
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
float c=3.6;
char k='m';
float sum=3.6+k;
float mul=3.6*k;
float sub=sum-k;
float div=sum/k;
cout<<"the sum value is "<<sum<<endl;
cout<<"the mul value is "<<mul<<endl;
cout<<"the sub value is "<<sub<<endl;
cout<<"the div value is "<<div<<endl;
int a=10;
int b=20;
int sum1=10+20;
int mul1=10*20;
int sub1=10-20;
int div1=10/20;
cout<<"*************************"<<endl;
cout<<"the sum value is "<<sum1<<endl;
cout<<"the mul value is "<<mul1<<endl;
cout<<"the sub value is "<<sub1<<endl;
cout<<"the div value is "<<div1<<endl;
}
output
the sum value is 112.6
the mul value is 392.4
the sub value is 3.6
the div value is 1.03303
*************************
the sum value is 30
the mul value is 200
the sub value is -10
the div value is 0
//the realibility is not there when we use different data types .it might be end up with incorrect results when compare with same data type values like integers