C++- typedef (creating data-type aliases)

 

Step: 1 Create a new C++ project

Step: 2 Edit the code

#include <iostream>
using namespace std;
int main()
{
typedef int class_size;
class_size Physics, Chemistry, Total;
cout << "Enter the number of students.\n";
cout << "Physics: ";
cin >> Physics;
cout << "Chemistry: ";
cin >> Chemistry;
Total = Physics + Chemistry;
cout << "\nNumber of students:";
cout << "\n No. of Students in Phyics: " << Physics;
cout << "\n No. of Chemistry: " << Chemistry << "\n";
cout << "\n Total No. of Students: " << Total << "\n\n";
return 0;
}
 

Step: 3 Runt time views

Entering 1st typedef alias (Physics)

Entering second alias "chemistry

Final tepedef alias "Total", calculated with two other aliases.