Rabu, 01 April 2026

C++ From Year 1995 File From "U"

 // Filename: U16OUT1.CPP

#include <iostream.h>

void doubleIt(int i);


void main()

{

  int i = 19;


  doubleIt(i);

  cout << "i is now " << i << endl;

  return;

}

//***************************************************

void doubleIt(int i)

{

  i *= 2;

  return;

}

===============================

// Filename: U16OUT2.CPP

#include <iostream.h>

void doubleIt(int *i);


void main()

{

  int i = 19;


  doubleIt(&i);

  cout << "i is now " << i << endl;

  return;

}

//***************************************************

void doubleIt(int *i)

{

  *i *= 2;

  return;

}

=========================

// Filename: UPPERFOR.CPP

// Using a for loop to print the uppercase letters

#include <iostream.h>

void main()

{

  char alph;


  cout << "The uppercase letters:" << endl;

  for (alph='A'; alph<='Z'; alph++)

    { cout << alph << ' '; }


  return;

}

========================

// Filename: USERAGE.CPP

// Uses a while loop to get an age from the user

#include <iostream.h>

void main()

 {

   int age;


   cout << "How old are you? ";

   cin >> age;


   while ((age < 5) || (age > 110))

     { 

       cout << "I'm not sure that I believe you are "

            << age << endl;

       cout << "Try again..." << endl << endl;

       cout << "How old are you? ";   // Get the age again

       cin >> age;

     }

   // The program continues if the user entered a reasonable age

   if (age < 16)

     { 

       cout << "Your curfew is at 11:30 pm" << endl;

       cout << "Have fun!"  << endl;

     }

   else

     {

       cout << "You're old enough to drive, so be careful ";

       cout << "out there!" << endl;

     }

   return;

 }

============================

// Filename: USRAVG2.CPP

// A for loop asks the user for values as determined by the

// number entered by the user. As the user enters each value, a compound

// assignment statement adds the values. After the loop ends

// and all three values are entered, the program prints an average.

// Notice that the average is divided by whatever value the

// user indicated.

#include <iostream.h>

void main()

{

  int count;         // The for loop's control variable

  int num;

  float value, avg;

  float total = 0;


  cout << "** An Average Program **" << endl << endl;


  cout << "How many values are there? ";

  cin >> num;

  // Loop num times

  for (count=0; count<num; count++)

    { cout << "What is the next value? ";

      cin >> value;

      total += value;    // Add to the total variable

    }


  // Now, compute and print the average

  avg = total / (float)num;

  cout << endl << "The average of your values is " << avg << endl;

  return;

}


Tidak ada komentar: