Created
July 6, 2019 15:53
-
-
Save theoctober19th/6eb0a044567bd3e8947d771dd32229ff to your computer and use it in GitHub Desktop.
Susmita Baini Solutions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
cout << "Welcome to C++ programming" << endl; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#define ASCII_0 48 | |
#define ASCII_9 57 | |
using namespace std; | |
int main() { | |
string num; | |
int sum=0; | |
cout << "Enter a number: "; | |
getline(cin, num); | |
for(int i=0; i<num.length(); i++){ | |
if(num[i] < ASCII_0 || num[i] > ASCII_9){ | |
cout << "Sorry. Non-digit character detected."; | |
return -1; | |
}else{ | |
sum += (num[i] - 48); | |
} | |
} | |
cout << "The sum of digits: " << sum << endl; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using namespace std; | |
int main() { | |
string master; | |
string input; | |
do { | |
getline(cin, input); | |
master.append(input); | |
master.append("\n"); | |
} while(input.compare("*") != 0); | |
cout << "The text you entered till now: " <<endl; | |
cout << master; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
float numA, numB, product; | |
cout << "Enter numbers A and B: "; | |
cin >> numA >> numB; | |
product = numA * numB; | |
cout << "A * B = " << product; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
float tempC, tempF; | |
cout << "Enter temperature in Celcius: "; | |
cin >> tempC; | |
tempF = 9.0/5.0 * tempC + 32; | |
cout << "Temperature in Fahrenheit= " << tempF; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int n; | |
cout << "Enter the value of n: "; | |
cin >> n; | |
float numArray[n]; | |
cout << "Enter " << n << " numbers: "; | |
for(int i=0; i<n; i++){ | |
cin >> numArray[i]; | |
} | |
float max=numArray[0], min=numArray[0]; | |
for(int i=0; i<n; i++){ | |
if(numArray[i] > max) | |
max = numArray[i]; | |
if(numArray[i] < min) | |
min = numArray[i]; | |
} | |
cout << "Maximum = " << max << endl << "Minimum = " << min << endl; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int n; | |
cout << "Enter the value of n: "; | |
cin >> n; | |
float numArray[n]; | |
cout << "Enter " << n << " numbers: "; | |
for(int i=0; i<n; i++){ | |
cin >> numArray[i]; | |
} | |
for (int i = 0; i < n-1; i++) | |
for (int j = 0; j < n-i-1; j++) | |
if (numArray[j] > numArray[j+1]) { | |
float foo = numArray[j]; | |
numArray[j] = numArray[j+1]; | |
numArray[j+1] = foo; | |
} | |
cout << "Sorted List: " << endl; | |
for(int i=0; i<n; i++){ | |
cout << numArray[i] << " "; | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <iomanip> | |
using namespace std; | |
int main() { | |
cout << "The text following the fullstop goes to new line." << endl; | |
cout << setw(10) << "Each" << setw(10) << "word" << setw(10) << "has" << setw(10) << "width" << setw(10) << "10" << setw(10) << "in" << setw(10) << "this" << setw(10) << "line." << endl; | |
cout << setw(100) << setfill('*') << "This line follows a set of asterisks." << endl; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
enum Color { Red, Green, Blue, Cyan, Magenta, Yellow }; | |
const char* getColorName(int i){ | |
switch (i) { | |
case Red: return "Red"; | |
case Green: return "Green"; | |
case Blue: return "Blue"; | |
case Cyan: return "Cyan"; | |
case Magenta: return "Magenta"; | |
case Yellow: return "Yellow"; | |
} | |
} | |
int main() { | |
int color; | |
cout << "Enter a color name: "; | |
cin >> color; | |
cout << "The color correponding to integer is: " << getColorName(color) << endl; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using namespace std; | |
int main() { | |
string name; | |
cout << "Enter your name: "; | |
getline(cin, name); | |
cout << "Hello, " << name << "!" << endl; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#define ASCII_a 97 | |
#define ASCII_z 122 | |
using namespace std; | |
int main() { | |
string name; | |
cout << "Enter a sentence: "; | |
getline(cin, name); | |
for(int i=0; i<name.length(); i++){ | |
char foo = name[i]; | |
if(foo >= ASCII_a && foo <= ASCII_z){ | |
name[i] -= 32; | |
} | |
} | |
cout << "The sentence in uppercase: " << name << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment