Sunday, June 19, 2016

Greeter Program in C++ Using Text File

This sample program is an class programming activity that I wrote five years ago in my programming class in C++. What does the program will do is to ask the users name and other information and then those information will be process and stored in a text file. This code will teach how to use text file using C++. I hope you will find my work useful.

 Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.


Program Listing


#include <iostream>
#include <fstream>


using namespace std;

main() {

    string name, address;
    int age=0;

    ofstream file("greet.txt");

    cout <<  "\n\t Greeter Version 1.0 ";
    cout << "\n\n";
    cout << "Enter your name         :=> ";
    getline(cin,name);
    cout << "\nEnter your address    :=> ";
    getline(cin,address);
    cout << "\nEnter your age        :=> ";
    cin >> age;

    cout << "\n\n";
    cout << "\nHello " << name << " " << " Welcome to USLS - Bacolod ";
    cout << "\n You home address is " << address;
    cout << "\n You are already " << age
         << " years old.";
    file << "\n\n";
    file << "\n ======== Greeter Version 1.0 =========";
    file << "\n\n";
    file << "\n Hello " << name << " " << " Welcome to USLS - Bacolod ";
    file << "\n You home address is " << address;
    file << "\n You are already " << age
         << " years old.";
    file.close();
    cout << "\n\n";
    system("pause");
}

No comments:

Post a Comment