Real-Life Example: Student Information
Let's create a program that uses various data types to store student information.
Example: Storing Student Information
Code Example
#include <iostream>
#include <string>
int main() {
std::string name = "Akila";
int age = 22;
char grade = 'A';
bool isGraduated = false;
double gpa = 3.85;
std::cout << "Student Information:\n";
std::cout << "Name: " << name << std::endl;
std::cout << "Age: " << age << std::endl;
std::cout << "Grade: " << grade << std::endl;
std::cout << "GPA: " << gpa << std::endl;
std::cout << "Graduated: " << (isGraduated ? "Yes" : "No") << std::endl;
return 0;
}
Explanation: This program declares variables of different data types to store a student's information and then displays it.
Key Takeaways
- Combining different data types allows for complex data representation.
- Real-life examples help solidify understanding of data types.
- Practice using data types in meaningful programs.