1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
#include "stdafx.h" /*Required regarding .NET for the console log */
#include <iostream> /*Required for data input/output ( cin>>/cout<< ) */
#include <string> /*Required to include strings ( words ) in the code */
using namespace std; /*The namespace used,in this case standard C++ (this has variable names and stuff ) */
//Declaration of a function to get the file size
void getSize (int a, float b,double c,short d,long e,unsigned f) {
//Getting the size allocated to each data ( all size output will be an int number )
int a1,b1,c1,d1,e1,f1;
a1 = sizeof(a);
b1 = sizeof(b);
c1 = sizeof(c);
d1 = sizeof(d);
e1 = sizeof(e);
f1 = sizeof(f);
//Printing the size
cout<<"int size is "<< a1<<" bytes"<<'\n'; /* '\n' is the same as endl */
cout<<"float size is "<< b1<<" bytes"<<endl;
cout<<"double size is "<< c1<<" bytes"<<endl;
cout<<"short size is "<< d1<<" bytes"<<endl;
cout<<"long size is "<< e1<<" bytes"<<endl;
cout<<"unsigned size is "<< f1<<" bytes"<<'\n';
//Exiting without return 0 because the type of this function is void (no data returned )
}
//Declaration of a function to print the values inserted
void varValues (int a, float b,double c,short d,long e,unsigned f) {
//Printing the values inserted by the user
cout<<a<<endl<<b<<endl<<c<<endl<<d<<endl<<e<<endl<<f;
//Exiting
}
//Main program (this is where the app starts from )
int main() {
//Declaration of variables
int a;
string x1,x2,x3,x4,x5,x6;
float b;
double c;
short d;
long e;
unsigned f;
int x;
string y;
//Asking the user to input all data
cout<<"Enter integer"<<endl;
cout<<"float"<<endl;
cout<<"double float"<<endl;
cout<<"short integer"<<endl;
cout<<"long integer"<<endl;
cout<<"unsigned integer"<<endl;
//Assigning the data to variables
cin>>a;
cin>>b;
cin>>c;
cin>>d;
cin>>e;
cin>>f;
//Asking the user for next step
A : cout<<"Enter 1 for data bytes,2 for variable values and 3 to exit"<<endl;
//Getting the input
cin>>x;
//Introducing the cases,here you can also use if/else but switch is faster if you deal with multiple choices
switch (x) {
case 1 :
getSize(a,b,c,d,e,f);
//Pausing
system("PAUSE");
goto A;
break;
case 2 :
varValues(a,b,c,d,e,f);
system("PAUSE");
goto A;
break;
case 3 :
B :cout<<"Are you sure you want to exit?"<<endl;
cout<<"Enter Y for yes and N for no"<<endl;
cin>>y;
if (y == "Y" ) {
//Pausing for user to hit "Enter"
system("PAUSE");
//Exiting without errors
return 0; }
else if (y == "N" ) {
/*Redirecting user */ goto A; }
else cout<<"Unrecognised input"<<endl;
goto B;
break;
default :
cout<<"Unrecognised input"<<endl;
goto A;
break;
//Exiting switch
}
cout<<"Have a nice day! :) ";
return 0;
}
|