C++ assignment
C++ assignment
#include <iostream>
#include <string>
#include <cctype>
int main() {
string input;
getline(cin, input);
string result;
if (isalpha(c)) {
result += c;
return 0;
#include <string>
int main() {
string input;
1
getline(cin, input);
cout << "Length of the string: " << length << endl;
return 0;
#include <iostream>
#include <string>
int main() {
return 0;
#include <string>
int main() {
getline(cin, str1);
str2 = str1;
2
cout << "The copied string is: " << str2 << endl;
return 0;
#include <iostream>
#include <string>
struct Student {
string name;
int age;
float gpa;
};
int main() {
Student student;
getline(cin, student.name);
3
return 0;
6. Write a C++ program to find the size of int, float, char and double in your system?
#include <iostream>
int main() {
cout << "Size of int: " << sizeof(int) << " bytes" << endl;
cout << "Size of float: " << sizeof(float) << " bytes" << endl;
cout << "Size of char: " << sizeof(char) << " bytes" << endl;
cout << "Size of double: " << sizeof(double) << " bytes" << endl;
return 0;
7. Write a C++ program to sort and print elements in Lexicographical order(Dictionary order)?
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
int main() {
sort(words.begin(), words.end());
4
}
return 0;
8. Write a C++ program that converts Fahrenheit to Celsius and vice versa?
#include <iostream>
int main ()
double fahrenheit ;
cin>>fahrenheit;
cout << fahrenheit << " Fahrenheit is equal to " << celsius << " Celsius" << endl;
celsius;
cin>>celsius;
fahrenheit = celsiusToFahrenheit(celsius);
cout << celsius << " Celsius is equal to " << fahrenheit << " Fahrenheit" << endl;
return 0;
5
return (fahrenheit - 32) * 5 / 9;
9. Write a C++ program that converts Decimal number to Binary and vice versa?
#include <iostream>
#include <bitset>
int main() {
bitset<8> binary(decimal);
cout << decimal << " in binary is " << binary.to_string() << endl;
cout << binaryStr << " in decimal is " << decimalFromBinary << endl;
return 0;
10.Write a C++ program that converts Uppercase to Lowercase and Lowercase to uppercase
letters?
#include <iostream>
#include <cctype>
6
int main() {
cout << uppercaseLetter << " in lowercase is " << lowercaseLetter << endl;
cout << lowercaseLetter2 << " in uppercase is " << uppercaseLetter2 << endl;
return 0;