SRM ELAB SOLUTIONS OOPS
I/O Operations 1
- Upper case conversion
- Digits in Words
- Country
- SRM Calculator
- Legends of Indian Cricket
Upper case conversion
#include <iostream>
#include <string>
using namespace std;
int main()
{
char s[30];
int i;
cin>>s;
for(i=0;i<=10;i++) {
if(s[i]>=97 && s[i]<=122)
{
s[i]=s[i]-32;
}
}
cout<<s;
return 0;
}
Digits in Words
#include <iostream>
using namespace std;
int main()
{
long int n, sum = 0, r;
cin >> n;
while (n > 0)
{
r = n % 10;
sum = sum * 10 + r;
n = n / 10;
}
n = sum;
while (n > 0)
{
r = n % 10;
switch (r)
{
case 1:
cout << "One ";
break;
case 2:
cout << "Two ";
break;
case 3:
cout << "Three ";
break;
case 4:
cout << "Four ";
break;
case 5:
cout << "Five ";
break;
case 6:
cout << "Six ";
break;
case 7:
cout << "Seven ";
break;
case 8:
cout << "Eight ";
break;
case 9:
cout << "Nine ";
break;
case 0:
cout << "Zero ";
break;
default:
cout << "tttt ";
break;
}
n = n / 10;
}
return 0;
}
Country
#include <iostream>
using namespace std;
int main()
{
int a;
cin >> a;
if (a > 17 && a < 60)
cout << "Eligible";
else
cout << "Not Eligible";
return 0;
}
SRM Calculator
#include <iostream>
using namespace std;
int main()
{
int op, b, c;
cin >> op;
cin >> b >> c;
switch (op)
{
case 1:
cout << b + c;
break;
case 2:
cout << b - c;
break;
case 3:
cout << b * c;
break;
case 4:
cout << b / c;
break;
break;
default:
cout << "Invalid Input";
break;
}
return 0;
}
Legends of Indian Cricket
#include <iostream>
using namespace std;
void expand(int);
int main()
{
int num;
cin >> num;
expand(num);
}
void expand(int value)
{
const char *const ones[20] = {"zero", "one", "two", "three", "four", "five", "six", "seven",
"eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen",
"eighteen", "nineteen"};
const char *const tens[10] = {"", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy",
"eighty", "ninety"};
if (value < 0)
{
cout << "minus ";
expand(-value);
}
else if (value >= 1000)
{
expand(value / 1000);
cout << " thousand";
if (value % 1000)
{
if (value % 1000 < 100)
{
cout << " and";
}
cout << " ";
expand(value % 1000);
}
}
else if (value >= 100)
{
expand(value / 100);
cout << " hundred";
if (value % 100)
{
cout << " and ";
expand(value % 100);
}
}
else if (value >= 20)
{
cout << tens[value / 10];
if (value % 10)
{
cout << " ";
expand(value % 10);
}
}
else
{
cout << ones[value];
}
return;
}
0 Comments