Skip to content

Commit 412afd5

Browse files
committed
6.1 Structs added
1 parent 49c312f commit 412afd5

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

7_Data_Structures/7_1_Structs.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
// Creating a s struct
6+
struct students {
7+
string name;
8+
float gpa;
9+
};
10+
11+
int main() {
12+
13+
students student; // Initialise students structure
14+
15+
student.name = "Akshay"; // Access the name and add string to it
16+
student.gpa = 5.0; // Access the gpa and add float to it.
17+
18+
cout << student.name << " has " << student.gpa << endl; // Print out its values.
19+
20+
return 0;
21+
}

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ C++ Notes
5151
- [5.6 File IO](#56-file-io)
5252
- [5.6.1 Reading Files](#561-reading-files)
5353
- [5.6.2 Writing File](#562-writing-file)
54+
- [6. Data Structures](#6-data-structures)
55+
- [6.1 Structs](#61-structs)
5456

5557
## 1 Requirements
5658

@@ -1130,3 +1132,27 @@ Reading a file in C++ can be done using `ifstream`, this data type has many func
11301132
[6_2_Writing_File.cpp](https://github.com/akshaybabloo/CPP-Notes/tree/master/6_File_IO/6_2_Writing_File.cpp)
11311133

11321134
Writing file can be done using `ofstring`, like `ifstring`, this data type provides the same functions - `open` and `close`. If a file already exists with that name, its over written, this can be changed using `ios::app` option that appends any string given to it.
1135+
1136+
1137+
## 6. Data Structures
1138+
1139+
_A data structure is a group of data elements grouped together under one name._ A structure can have multiple data types grouped together to form a way of representation.
1140+
1141+
### 6.1 Structs
1142+
1143+
[7_1_Structs.cpp](https://github.com/akshaybabloo/CPP-Notes/tree/master/7_Data_Structures/7_1_Structs.cpp)
1144+
1145+
It has a group of data types that can be called by name. It can be represented as:
1146+
1147+
```cpp
1148+
struct STRUCT_NAME {
1149+
DATA_TYPE NAME;
1150+
};
1151+
```
1152+
1153+
You can access them as:
1154+
1155+
```cpp
1156+
STRUCT_NAME some_name;
1157+
some_name.NAME
1158+
```

0 commit comments

Comments
 (0)