I'm on the school's network hard drive, looking around, out of curiousity for what they use in their C++ class. Visual Basic.NET isn't a challenge for me, so it's discouraging and that is why I'm currently getting bad marks until I make some stuff up/settle down.
Anyhow, I'm going to post a few programs here from the drive, and I want anybody who can find errors, etc. with the programs to post them. I can see a few, but this is more or less a thought of, I'd take the course, as it would be fun for me since I do c & c++ during my free time, but, I think this particular course is a bit dodgy.
loop example:
Code:
#include <iostream.h>
void main(void)
// This program calculates the average
// of five user-entered numbers.
{
int count;
float num, total, average;
total = 0.0;
for (count = 0; count < 5; count++)
{
cout << "Enter a number: ";
cin >> num;
total = total + num;
}
average = total / count;
cout << "\nThe average of the data entered is " << average;
}
array example:
Code:
/* Using an array to BUILD PRICE */
/* Include Files */
#include <iostream.h>
void main()
{
const int ARRAY_NUM = 2;
int price[ARRAY_NUM] = {0};
float quantity[ARRAY_NUM];
float amount[ARRAY_NUM];
int incr;
//magic formulas for printing decimal points
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
// Display directions
cout << "*********************************************************************";
cout << "\n The Great Widget Company";
cout << "\n*******************************************************************";
cout << "\nThis program will ask you for prices and quantity of Widgets";
cout << "\nThen the program will display a table showing quantity, Price,";
cout << "and the amount of your purchases";
cout << "\n*******************************************************************\n\n";
/* Building array */
for (incr = 0; incr < ARRAY_NUM; ++incr)
{
cout << "Enter a price: ";
cin >> price[incr];
if (price[incr] == 9999)
break;
else
{
cout << "\nEnter the quantity purchased: \n";
cin >> quantity[incr];
amount[incr] = quantity[incr];
}
}
// Printing the table headings
cout << "\n-----------------------------------------------------------------------";
cout << "\n Purchasing Report";
cout << "\n Quantity Price Amount";
cout << "\n -------- ----- ------\n";
// Print the array
for (incr = 0; incr < ARRAY_NUM; ++incr)
{
cout << " " << quantity[incr] << " " << price[incr];
cout << " " << amount[incr] << "\n";
}
cout << "\n\n Thank you for Using Great Widgets\n";
}
function example:
Code:
/* This program has two functions: Main and total_cost */
#include <iostream.h>
//function prototype
void total_cost(int, double);
//Global variable
double subtotal;
void main( void )
{
double price;
int number;
cout << "Enter the number of items purchased: ";
cin >> number;
cout << "Enter the price per item $";
cin >> price;
// function call
total_cost(number, price);
//magic formulas for printing decimal points
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << number << " item at "
<< "$" << price << " each.\n"
<< "Final bill, including tax, is $" << subtotal
<< endl;
}
//function heading
void total_cost(int number_par, double price_par)
{
const double TAX_RATE = 0.05; //5% SALES TAX
subtotal = price_par * number_par;
subtotal = subtotal + (subtotal * TAX_RATE);
}