- #include<iostream>
- #include<string>
- using namespace std;
- int main ()
- {
- /* cout<< "Hello world"<<endl; // Prints Hello world
- cout<< "I am a C++ Program"<<endl;
- for (int i = 1; i<= 100; i++) if (i%5==0) cout<<"i = "<<i<<endl;
- return 0; //Terminate the program
- */
- /* cout <<"What the Hell!"<<endl;
- const int rows = 3;
- const int cols = 6;
- int numbers[rows][cols];
- int Table[rows][cols] = {{1,2,3,4,5,6},{5,4,3,6,7,8}, {9,6,7,5,4,3}};
- for (int r = 0; r<rows; ++r)
- for (int c = 0; c<cols; ++c)
- numbers[r][c] = 0;
- for(int r = 0; r<rows; ++r) {
- for (int c = 0; c<cols; ++c)
- cout<<" "<<numbers[r][c]<<" ";
- cout<<endl;
- }
- return 0;
- */
- const int rows = 6;
- const int cols = 6;
- int Total = 0;
- double average = 0.0;
- int grades[rows][cols] = {{89, 98, 78, 79, 100, 96}, //initialization of 6 by 6 array
- {97, 87, 77, 80,90, 95},
- {86, 88, 99, 94, 92, 84},
- {75, 85, 81, 83, 98, 90},
- {80, 76, 77, 89, 96, 77},
- {90,80,78,91, 93, 100}};
- for (int r = 0; r < rows; ++r) {cout<<"Students"<<r+1<<"Marks"<<" :";
- for (int c = 0; c < cols; ++c){
- cout<<grades[r][c]<<" ";
- Total + = grades[r][c];
- }
- average = Total/cols;
- cout<<"Average is"<<average<<endl;
- Total = 0;
- average = 0.0;
- }
- return 0;
- }
-
- Active Topics
-
-
- by Eli 11 hours ago All in One: YouTube, TED, X, Facebook and Instagram Reels, Videos, Images and Text Posts View the latest post Replies 328 Views 37830
- by Eli 11 hours ago Re: What is in Your Mind? View the latest post Replies 705 Views 303563
- by Eli 4 days ago Russia Invades Ukraine View the latest post Replies 663 Views 238553
- by Eli 6 days ago PySpark for Large Data Processing View the latest post Replies 1 Views 7935
- by Eli 1 week ago President Museveni's Speech During International Development Association (IDA) Summit View the latest post Replies 1 Views 325
- by Eli 1 week ago From Simple Linear Regression Analysis to Covariance & Correlation to Independent Determinant, and R-Squared View the latest post Replies 11 Views 24936
- by Eli 2 weeks ago Collection of Greatest Christian Hymns of all Times View the latest post Replies 34 Views 70534
- by Eli 2 weeks ago Pondering Big Cosmology Questions Through Lectures and Dialogues View the latest post Replies 34 Views 58513
- by Eli 2 weeks ago Programmatically Manipulate Files: Renaming, Reading, Writing, Deleting, and Moving Files Between Folders View the latest post Replies 7 Views 18632
- by Eli 3 weeks ago Iran Launches Retaliatory Attack Against Israel, and Israel Retaliates by Attacking Iranian Isfahan Millitary Base View the latest post Replies 28 Views 20948
-
Simple C++ Program
- Eli
- Senior Expert Member
- Reactions: 183
- Posts: 5387
- Joined: 9 years ago
- Location: Tanzania
- Has thanked: 75 times
- Been thanked: 88 times
- Contact:
Hello World, here is a simple C++ program, compile and execute it to see what it does!
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
- Eli
- Senior Expert Member
- Reactions: 183
- Posts: 5387
- Joined: 9 years ago
- Location: Tanzania
- Has thanked: 75 times
- Been thanked: 88 times
- Contact:
When programming, especially, in C-type programming languages such as C++ we need to store the variables in a computer memory. Before the computer stores any variable, it needs to know the type of data we want to store in it. The reason the computer has to know in advance the type of data before storing it, is that different data types occupy different memory sizes in a computer. It will not take the same amount of memory to store a simple number as to store a single letter or a large number. Furthermore, the variables (say numbers, characters etc.,) are not going to be interpreted the same way by computer in storage. Simply a computer needs to spare different memory partitions appropriate for storing different data types. That is why in order to use a variable in C++, you must first declare it to specify which data type you want it to be.
Computer memory is organized in bytes - the minimum manageable amount of memory in C++. One byte is composed of 4 bits. A bit (in digital storage) is either 0 or 1 and not otherwise.
A byte can store a relatively small unit of data, for example, one single character "char" or a small integer "int", generally an integer between 0 and 255. In addition, the computer can do manipulation to form more complex data types by grouping several bytes. We can therefore think of computer memory as a long tape of bytes.
Float and double variable types differ in the way they store the values. Double and float are both floating point numbers, their main difference is in "precision". Think of precision as "a measure of the detail in which the quantity is expressed".
But, in relation to computer memory, precision refers to as the number of bits used to hold the fractional part of floating-point numbers. The more precision a system uses, the more exactly it can represent fractional quantities.
A "single-precision floating-point format" is a computer number format, usually occupying 4 bytes (32 bits) in computer memory while
"double-precision floating-point format" is a computer number format, usually occupying 8 bytes (64 bits) in computer memory . This means a double has 2 times the precision of float, implying that double-precision floating point number can represent fractional quantities much more accurately than single-precision.
Generally speaking, double has 15 - 16 decimal digits of precision while float has 6 - 7 decimal digits of precision.
However,
float: Floating point number (single-precision) can be stored in a computer memory of size 4 bytes and the value range is \(\pm 3.4e^{\pm 38} \)
double: Double-precision floating point number (double-precision float) can be stored in a computer memory of size 8 bytes and the value range is \(\pm 1.7e^{\pm 308} \)
Computer manages memory by assigning unique address to each byte, where each address is represented by a single integer.
It is important to note that, memory sizes for storing the data types (int, char, float, double etc.,) and their value ranges depend on the system architecture under which the program is compiled, i.e., whether the system is 32-bit or 64-bit. For example, depending on the system environment an integer memory can either be 32 bits or 64 bits.
Memory management is central in C++ programming.
Computer memory is organized in bytes - the minimum manageable amount of memory in C++. One byte is composed of 4 bits. A bit (in digital storage) is either 0 or 1 and not otherwise.
A byte can store a relatively small unit of data, for example, one single character "char" or a small integer "int", generally an integer between 0 and 255. In addition, the computer can do manipulation to form more complex data types by grouping several bytes. We can therefore think of computer memory as a long tape of bytes.
Float and double variable types differ in the way they store the values. Double and float are both floating point numbers, their main difference is in "precision". Think of precision as "a measure of the detail in which the quantity is expressed".
But, in relation to computer memory, precision refers to as the number of bits used to hold the fractional part of floating-point numbers. The more precision a system uses, the more exactly it can represent fractional quantities.
A "single-precision floating-point format" is a computer number format, usually occupying 4 bytes (32 bits) in computer memory while
"double-precision floating-point format" is a computer number format, usually occupying 8 bytes (64 bits) in computer memory . This means a double has 2 times the precision of float, implying that double-precision floating point number can represent fractional quantities much more accurately than single-precision.
Generally speaking, double has 15 - 16 decimal digits of precision while float has 6 - 7 decimal digits of precision.
However,
float: Floating point number (single-precision) can be stored in a computer memory of size 4 bytes and the value range is \(\pm 3.4e^{\pm 38} \)
double: Double-precision floating point number (double-precision float) can be stored in a computer memory of size 8 bytes and the value range is \(\pm 1.7e^{\pm 308} \)
Computer manages memory by assigning unique address to each byte, where each address is represented by a single integer.
It is important to note that, memory sizes for storing the data types (int, char, float, double etc.,) and their value ranges depend on the system architecture under which the program is compiled, i.e., whether the system is 32-bit or 64-bit. For example, depending on the system environment an integer memory can either be 32 bits or 64 bits.
Memory management is central in C++ programming.
TSSFL -- A Creative Journey Towards Infinite Possibilities!
-
- Information
-
Who is online
Users browsing this forum: No registered users and 1 guest