~jordan31/learningcpp

4b35c12136a1f0ab86b0b430a161ab202fbb3d03 — Jordan 3 months ago
Init repo
2 files changed, 88 insertions(+), 0 deletions(-)

A c++_practice.cpp
A sorting_algor.cpp
A  => c++_practice.cpp +82 -0
@@ 1,82 @@
#include <iostream>
#include <climits> //integer limits header file

int main() {
	//Write a program in C++ to print a welcome text in a seperate line
	std::cout << "Welcome and hello User!" << std::endl;
	
	//Write a program to print sum of two numbers
	std::cout << "\nPlease enter two (2) numbers to calculate the sum." << std::endl;
	int x, sum = 0;
	for(int i = 1; i < 3; i++) {
		std::cout << i << " num: ";
		std::cin >> x;
		sum = x + sum;
	}
	std::cout << "The answer is: " << sum << std::endl;
	
	//Write a program that finds the size of fundamental data types
	std::cout << "\nPrinting the sizeof fundamental data types.\n"
	<< "The sizeof(char) is: " << sizeof(char) << "bytes\n"
	<< "The sizeof(short) is: " << sizeof(short) << "bytes\n"
	<< "The sizeof(int) is: " << sizeof(int) << "bytes\n"
	<< "The sizeof(long) is: " << sizeof(long) << "bytes\n"
	<< "The sizeof(long long) is: " << sizeof(long long) << "bytes\n"
	<< "The sizeof(float) is: " << sizeof(float) << "bytes\n"
	<< "The sizeof(double) is: " << sizeof(double) << "bytes\n"
	<< "The sizeof(long double) is: " << sizeof(long double) << "bytes\n"
	<< "The sizeof(bool) is: " << sizeof(bool) << "bytes" << std::endl;	
	
	//Write a program to print the sum of two numbers using variables
	int a, b;
	a = 50;
	b = 55;
	std::cout << "\nSum of 50 + 55 is: " << a + b << std::endl;
	
	//Write a program to check the upper and lower limits of integer
	//This uses the climits header file
	std::cout << "\nMax & Min limits of interger:" << "\n-----------------------------------" << std::endl;
	std::cout << "Max limit of (int) type: " << INT_MAX << std::endl;
	std::cout << "Min limit of (int) type: " << INT_MIN << std::endl;
	std::cout << "Max limit of (unsigned int) type:	" << UINT_MAX << std::endl;
	std::cout << "Max limit of (long long) type: " << LLONG_MAX << std::endl;
	std::cout << "Min limit of (long long) type: " << LLONG_MIN << std::endl;
	std::cout << "Max limit of (unsigned long long) type: " << ULONG_MAX << std::endl;
	std::cout << "The Bits contain in char data type: " << CHAR_BIT << std::endl;
	std::cout << "Max limit of char data type: " << CHAR_MAX << std::endl;
	std::cout << "Min limit of char data type: " << CHAR_MIN << std::endl;
	std::cout << "Max limit of signed char data type: " << SCHAR_MAX << std::endl;
	std::cout << "Min limit of signed char data type: " << SCHAR_MIN << std::endl;
	std::cout << "Max limit of unsigned char data type: " << UCHAR_MAX << std::endl;
	std::cout << "Min limit of short data type: " << SHRT_MIN << std::endl;
    std::cout << "Max limit of short data type: " << SHRT_MAX << std::endl;
    std::cout << "Max limit of unsigned short data type: " << USHRT_MAX << std::endl;
    
    //Swap two numbers using a temp variable
    std::cout << "\nSwap two numbers, 25 and 39." << std::endl;
    a = 25;
    b = 39;
    std::cout << "a =" << a << " b =" << b << std::endl;
    x = a;
    a = b;
    b = x;
    std::cout << "a ="  << a << " b =" << b << std::endl;
    
    // Write a program to calculate the volume of a cube
    std::cout << "\nFind volume of CUBE, cube side = 5.\n 5*5*5" << std::endl;
    std::cout << "Cube's volume = " << 5*5*5 << "in (cubic inches)" << std::endl;
    
    //Calculate the volume of a sphear
    std::cout << "\nCalculate the volume of a sphear. Radius = 6.\n v = 4/3*3.14*r" << std::endl;
    double v = 0;
    x = 6 * 6 * 6;
    double aa;
    aa = 4 / 3;
    double bb = 3.14;
    
    v = aa * bb * x;
    std::cout << "Volume of sphear is: " << (4*3.14*216)/3 << "    " << v << std::endl;
    
    
	return 0;
}

A  => sorting_algor.cpp +6 -0
@@ 1,6 @@
#include <iostream>

int main() {
	std::cout << "Hello World" << std::endl;
	return 1;
}