Can You Imagine 5 Examples of Minimal C++ Programmes During 1986?
- User
Can You Imagine 5 Examples of Minimal C++ Programmes During 1986?
- Assistant
Can You Imagine 5 Examples of Minimal C++ Programmes During 1986?
In 1986, the C++ programming language was still in its early stages of development. Bjarne Stroustrup had published "The C++ Programming Language" in 1985, and the language was slowly gaining popularity. At this point in time, C++ was essentially "C with Classes", and many of the features we associate with modern C++ were not yet introduced or not fully developed.
Here are five examples of simple programs you could have written in C++ in 1986, considering the limited features and standard library support available at the time:
#include <iostream.h>
main() {
cout << "Hello, World!\n";
return 0;
}
#include <iostream.h>
main() {
char name[50];
cout << "Enter your name: ";
cin >> name;
cout << "Hello, " << name << "!\n";
return 0;
}
#include <iostream.h>
int add(int a, int b) {
return a + b;
}
main() {
int sum = add(5, 3);
cout << "The sum is: " << sum << endl;
return 0;
}
#include <iostream.h>
class Rectangle {
int width, height;
public:
Rectangle(int x, int y) : width(x), height(y) {}
int area() { return width * height; }
};
main() {
Rectangle rect(3, 4);
cout << "Area of the rectangle: " << rect.area() << endl;
return 0;
}
#include <fstream.h>
#include <iostream.h>
main() {
char data[100];
ofstream ofile; // Declare output file stream
ofile.open("example.dat");
cout << "Writing to the file" << endl;
cout << "Enter your name: ";
cin.getline(data, 100);
// write inputted data into the file
ofile << data << endl;
ofile.close();
ifstream ifile; // Define input file stream
ifile.open("example.dat");
cout << "Reading from the file" << endl;
ifile >> data; // read data from file into array
cout << data << endl;
ifile.close();
return 0;
}
Keep in mind that the specific forms of these programs may vary slightly depending on the actual state of C++ compilers at that time. I have used the .h extensions and omitted using namespace std;, as the standard library was not yet standardized in the form we know today. The iostream library is platform-specific and its use evolved over time. These examples use syntax and library functionality that would likely have been supported by the early implementations of C++, despite not being idiomatic by today's C++ standards.
Not yet included in a published release.