Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,151,114 members, 7,811,133 topics. Date: Sunday, 28 April 2024 at 01:44 AM

A Thread For C++ Programs - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / A Thread For C++ Programs (975 Views)

A Thread On My Experiment With Reinforcement Learning & Artificial Intelligence. / A Thread For Tutorial On Python Programming / Whatsapp Group For C++ Beginners (2) (3) (4)

(1) (2) (Reply) (Go Down)

A Thread For C++ Programs by Tim1212(m): 9:06am On Aug 20, 2020
#include <iostream>

using namespace std;

int main ()
{
int length;
int width;
double perimeter;
double area;

length = 6;
width = 4;
perimeter = 2 * ( length + width );
area = length * width;

cout << "Length = " << length << endl;
cout << "width = " << width << endl;
cout << "Area = " << area << endl;
cout << " Perimeter = " << perimeter << endl;

return 0;
}

I will be explaining every single program starting from the beginning.
Re: A Thread For C++ Programs by Tim1212(m): 9:09am On Aug 20, 2020
#include <iostream>
using namespace std;

int main ()
{
double length;
double width;
double area;
double perimeter;
cout << "program to compute and output the perimeter and "
<<"area of a rectangle." << endl;
length = 6.0;
width = 4.0;
perimeter = 2 * (length + width);
area = length * width;

cout << "Length = " << length << endl;
cout << "width = " << width << endl;
cout << "Perimeter = " << perimeter << endl;
cout << "Area = " << area << endl;

return 0;
}
Re: A Thread For C++ Programs by damdam995(m): 9:09am On Aug 20, 2020
Wetin be this

1 Like

Re: A Thread For C++ Programs by Tim1212(m): 9:10am On Aug 20, 2020
#include <iostream>
using namespace std;
int main ()
{
int feet;
int inches;

cout << "Enter two integers separated by one or more spaces: ";
cin >> feet >> inches;
cout << endl;

cout << "Feet = " << feet << endl;
cout << "Inches = " << inches << endl;

return 0;
}
Re: A Thread For C++ Programs by Tim1212(m): 9:14am On Aug 20, 2020
#include <iostream>

using namespace std;

int main ()
{
cout << 29 / 4 << endl;
cout << "Hello There. " << endl;
cout << 12 << endl;
cout << "4 + 7 " << endl;
cout << 4 + 7 << endl;
cout << 'A' << endl;
cout << "4 + 7 = " << 4 + 7 << endl;
cout << 2 + 3 * 5 << endl;
cout << "Hello \nthere. " << endl;

return 0;
}
Re: A Thread For C++ Programs by Tim1212(m): 9:15am On Aug 20, 2020
#include <iostream>

using namespace std;
int main ()
{
int a,b;
a = 65;
b = 78;

cout << 29 / 4 << endl;
cout << 3.0 / 2 << endl;
cout << "Hello there.\n";
cout << 7 << endl;
cout << 3 + 5 << endl;
cout << "3 + 5 ";
cout << "** ";
cout << endl;
cout << 2 + 3 * 6 << endl;
cout << "a" << endl;
cout << a << endl;
cout << b << endl;

return 0;
}
Re: A Thread For C++ Programs by Tim1212(m): 9:17am On Aug 20, 2020
#include <iostream>
using namespace std;

int main()
{
int num1, num2;

cout << "Enter any two intergers: ";
cin >> num1 >> num2;
cout << endl;

cout << "The two intergers entered are " << num1 << " and " << num2 << endl;

if (num1 > num2)
cout << "The larger number is " << num1 << endl;
else
cout << num2 << " is lesser " << endl;
if (num2 > num1)
cout << "The larger number is " << num2 << endl;
else
cout << num2 << "is lesser " << endl;

return 0;

}
Re: A Thread For C++ Programs by Tim1212(m): 9:18am On Aug 20, 2020
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
string name;
int numOfVolunteers;
int numOfBoxesSold;
int totalNumOfBoxesSold;
int counter;
double costOfOneBox;

cout << fixed << showpoint << setprecision(2);

cout << "Enter the number of volunteers: ";
cin >> numOfVolunteers;
cout << endl;

totalNumOfBoxesSold = 0;
counter = 0;

while (counter < numOfVolunteers)
{
cout << "Enter the volunteer's name"
<< " and the number of boxes sold: ";
cin >> name >> numOfBoxesSold;
cout << endl;

totalNumOfBoxesSold =totalNumOfBoxesSold + numOfBoxesSold;
counter++;
}

cout << "The total number of boxes sold: "
<< totalNumOfBoxesSold << endl;
cout << "Enter the cost of one box: ";
cin >> costOfOneBox;
cout << endl;
cout << "The total money made by selling "
<< "cookies: $"
<< totalNumOfBoxesSold * costOfOneBox << endl;
if (counter != 0)
cout << "The average number of "
<< "boxes sold by each volunteer: "
<< totalNumOfBoxesSold / counter << endl;
else
cout << "No input. " << endl;
return 0;
}
Re: A Thread For C++ Programs by Tim1212(m): 9:20am On Aug 20, 2020
#include <iostream>
#include <cmath>
#include <cctype>
#include <iomanip>

using namespace std;

int main()
{
int num;
double firstNum, secondNum;
char ch = 'T';

cout << fixed << showpoint << setprecision(2) << endl;

cout << " Is " << ch << " a lowercase letter? "
<< isupper(ch) << endl;
cout << " Lowercase A is " << static_cast<char>(tolower('A')) << endl;

cout << " 4.5 to the power 6.0 = " << pow(4.5, 6.0) << endl;

cout << " Enter two decimal numbers: ";
cin >> firstNum >> secondNum;
cout << endl;

cout << " FIRST NUM: " << firstNum << " to the power of "
<< secondNum << " = " << pow(firstNum, secondNum) << endl;

cout << " 5.0 to the power of 4 = " << pow(5.0, 4) << endl;

firstNum = firstNum + pow(3.5, 7.2);
cout << " firstNum = " << firstNum << endl;

num = -32;
cout << " Absolute value of " << num << " = " << abs(num) << endl;

cout << " Square root of 28.00 = " << sqrt(28.00) << endl;

return 0;

}
Re: A Thread For C++ Programs by Tim1212(m): 9:25am On Aug 20, 2020
#include <iostream>

using namespace std;

const double CONVERSION = 2.54;
const int INCHES_IN_FOOT = 12;
const int CENTIMETETERS_IN_METER = 100;

void showChoice();
void feetAndIchesToMeterAndCent(int f, int in,
int& mt, int& ct);
void meterAndCentToFeetAndIches(int mt, int ct,
int& f, int& in);

int main()
{
int feet, inches;
int meters, centimeters;
int choice;

do
{
showChoice();
cin >> choice;
cout << endl;

switch (choice)
{
case 1:
cout << "Enter feet and iches: ";
cin >> feet >> inches;
cout << endl;
feetAndIchesToMeterAndCent(feet, inches,
meters, centimeters);
cout << feet << " feet(foot), "
<< inches << " inch(es) = "
<< meters << " meter(s), "
<< centimeters << " centimeter(s). " << endl;
break;
case 2:
cout << "Enter meter and centimeter: ";
cin >> meters >> centimeters;
cout << endl;
meterAndCentToFeetAndIches(meters, centimeters,
feet, inches);
cout << meters << " meter(s), "
<< centimeters << " centimeter(s) = "
<< feet << " feet(foot), "
<< inches << " inch(es). "
<< endl;
break;
case 99:
break;
default:
cout << "Invalid input." << endl;
}
}
while (choice != 99);
return 0;
}
void showChoice()
{
cout << "Enter--" << endl;
cout << "1: To convert from feet and inches to meters "
<< "and centimeters." << endl;
cout << "2: To convert from meters and centimeters to feet "
<< " and inches " << endl;
cout << "99: To quit the program." << endl;
}
void feetAndIchesToMeterAndCent(int f, int in,
int& mt, int& ct)
{
int inches;
inches = f * INCHES_IN_FOOT + in;
ct = static_cast<int>(inches * CONVERSION);
mt = ct / CENTIMETETERS_IN_METER;
ct = ct % CENTIMETETERS_IN_METER;
}
void meterAndCentToFeetAndIches(int mt, int ct,
int& f, int& in)
{
int centimeters;
centimeters = mt * CENTIMETETERS_IN_METER + ct;
in = static_cast<int>(centimeters / CONVERSION);
f = in / INCHES_IN_FOOT;
in = in % INCHES_IN_FOOT;
}
Re: A Thread For C++ Programs by Tim1212(m): 9:29am On Aug 20, 2020
#include <iostream>

using namespace std;

const int MIN_PER_HOUR = 60;
const int SEC_PER_MIN = 60;

int main()
{
int second, minute, hour;
int temp;

cout << " Enter the elaps time in seconds: ";
cin >> temp;
cout << endl;

cout << " The elaps time you entered is " << temp << endl;

second = temp % SEC_PER_MIN;

temp = temp / SEC_PER_MIN;

minute = temp % MIN_PER_HOUR;

hour = temp / MIN_PER_HOUR;

cout << " The elaps time you entered is ";
cout << hour << ":" << minute << ":" << second << endl;

return 0;
}
Re: A Thread For C++ Programs by Najdorf: 9:30am On Aug 20, 2020
undecided
Re: A Thread For C++ Programs by Tim1212(m): 9:30am On Aug 20, 2020
#include <iostream>

using namespace std;

int main()
{
int fahrenheit;
double celsius;

cout << "Enter temperature in Fahrenheit: ";
cin >> fahrenheit;
cout << endl;

celsius = static_cast<int>
(5.0 / 9 * (fahrenheit - 32) + 0.5 );

cout << fahrenheit << " degree F = "
<< celsius << " degree C. " << endl;

return 0;

}
Re: A Thread For C++ Programs by Tim1212(m): 9:32am On Aug 20, 2020
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

int main()

{
string movieName;
double childTicketPrice;
double adultTicketPrice;
int noOfAdultTicketsSold;
int noOfChildTicketsSold;
double percentDonation;
double grossAmount;
double amountDonated;
double netSaleAmount;

cout << fixed << showpoint << setprecision(2);

cout << "Enter the movie name: ";
getline(cin, movieName);
cout << endl;

cout << "Enter the price of an adult ticket: ";
cin >> adultTicketPrice;
cout << endl;

cout << "Enter the price a child ticket: ";
cin >> childTicketPrice;
cout << endl;

cout << "Enter number of adult ticket sold: ";
cin >> noOfAdultTicketsSold;
cout << endl;

cout << "Enter number of child ticket sold: ";
cin >> noOfChildTicketsSold;
cout << endl;

cout << "Enter the percentage of donation: ";
cin >> percentDonation;
cout << endl << endl;

grossAmount = adultTicketPrice * noOfAdultTicketsSold +
childTicketPrice * noOfChildTicketsSold;

amountDonated = grossAmount * percentDonation / 100;

netSaleAmount = grossAmount - amountDonated;

cout << "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"
<< "-*-*-*-*-*-*-*-*-*-*-*-*-*-*" << endl;
cout << left << setfill('.') << setw(35) << "Movie Name: "
<< right << " " << movieName << endl;
cout << left << setw(35) << "Number of Tickets Sold: "
<< setfill(' ') << right << setw(10)
<< noOfAdultTicketsSold + noOfChildTicketsSold
<< endl;
cout << setfill('.') << left << setw(35) << "Gross Amount: "
<< setfill(' ') << right << " $"
<< setw(cool << grossAmount << endl;
cout << setfill('.') << left << setw(35)
<< "Percentage of Gross Amount Donated: "
<< setfill(' ') << right
<< setw(9) << percentDonation << '%' << endl;
cout << setfill('.') << left << setw(35)
<< "Amount Donated: "
<< setfill(' ') << right << " $"
<< setw(cool << amountDonated << endl;
cout << setfill('.') << left << setw(35) << "Net Sale: "
<< setfill(' ') << right << " $"
<< setw(cool << netSaleAmount << endl;

return 0;

}
Re: A Thread For C++ Programs by Tim1212(m): 9:35am On Aug 20, 2020
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;

int main()
{
ifstream inFile;
ofstream outFile;

double test1, test2, test3, test4, test5;
double average;

string name;

inFile.open("test.dat"wink;
outFile.open("testavg.out"wink;

outFile << fixed << showpoint << setprecision(2);

cout << "processing data..........." << endl << endl;

getline(inFile, name);
outFile << "Student name: " << name << endl;

inFile >> test1 >> test2 >> test3 >> test4 >> test5;
outFile << "Test score: " << setw(6) << test1
<< setw(6) << test2 << setw(6) << test3
<< setw(6) << test4 << setw(6) << test5
<< endl;

average = (test1 + test2 + test3 + test4 + test5 ) / 5.0;

outFile << "Average test score: " << setw(6) << average
<< endl;

inFile.close();
outFile.close();

return 0;
}
Andrew Miller Malik
87.50 89 65.75 37 98.50

Student name: Andrew Miller Malik
Test score: 87.50 89.00 65.75 37.00 98.50
Average test score: 75.55
Re: A Thread For C++ Programs by Tim1212(m): 9:36am On Aug 20, 2020
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;

int main()
{

ifstream inFile;
ofstream outFile;

double test1, test2, test3, test4, test5;
double average;

string firstName;
string secondName;

inFile.open("test.dat"wink;

if (!inFile)

{
cout << " Cannot open the file. "
<< "the program terminates." << endl;
return 1;
}

outFile.open("testavg.out"wink;

outFile << fixed << showpoint << setprecision(2);

cout << "processing data." << endl;

inFile >> firstName >> secondName;
outFile << "Student name: " << firstName << " " << secondName << endl;

inFile >> test1 >> test2 >> test3 >> test4 >> test5;

outFile << "Test scores: " << setw(6) << test1
<< setw(6) << test2 << setw(6) << test3
<< setw(6) << test4 << setw(6) << test5
<< endl;

average = (test1 + test2 + test3 + test4 + test5) / 5.0;

outFile << "Average test score: " << setw(6) << average << endl;

inFile.close();
outFile.close();

return 0;
}

Student name: Timothy Ezike
Test scores: 63.93 83.20 23.40 67.21 45.89
Average test score: 56.73
Re: A Thread For C++ Programs by Tim1212(m): 9:38am On Aug 20, 2020
#include <iostream>

using namespace std;

int main()
{
char grade;
int score;

cout << "Enter a test score between 0 and 100: ";
cin >> score;
cout << endl;

switch (score / 10)
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
grade = 'F';
break;
case 6:
grade = 'D';
break;
case 7:
grade = 'C';
break;
case 8:
grade = 'B';
break;
case 9:
case 10:
grade = 'A';
break;
default:
cout << "Invalid test score." << endl;
}

cout << "your grade is " << grade << endl;

return 0;
}
Re: A Thread For C++ Programs by Tim1212(m): 9:39am On Aug 20, 2020
#include <iostream>
#define NDBUG
#include <cassert>

using namespace std;

int main()

{
int numerator, denominator, quotient;

cout << "Enter a quotient of two integers: ";
cin >> numerator >> denominator;
cout << endl;

assert(denominator != 0);
quotient = numerator / denominator;

cout << "Quotient = " << quotient << endl;

return 0;
}
Re: A Thread For C++ Programs by Tim1212(m): 9:40am On Aug 20, 2020
#include <iostream>
#include <iomanip>

using namespace std;

const double RES_BILL_PROC_FEES = 4.50;
const double RES_BASIC_SERC_COST = 20.50;
const double RES_COST_PREM_CHANNEL = 7.50;

const double BUS_BILL_PROC_FEES = 15.00;
const double BUS_BASIC_SERV_COST = 75.00;
const double BUS_BASIC_CONN_COST = 5.00;
const double BUS_COST_PREM_CHANNEL = 50.00;

int main()

{
int accountNumber;
char customerType;
int numOfPremChannel;
int numOfBasicServConn;
double amountDue;

cout << fixed << showpoint << setprecision(2);

cout << "This program computes a cable "
<< "bill. " << endl;
cout << "Enter account number (an integer): ";
cin >> accountNumber;
cout << endl;

cout << "Enter customer type: "
<< "R or r (Residential), "
<< "B or b (Business): ";
cin >> customerType;
cout << endl;

switch (customerType)
{
case 'R':
case 'r':
cout << "Enter the number"
<< " of premium channels: ";
cin >> numOfPremChannel;
cout << endl;

amountDue = RES_BILL_PROC_FEES + RES_BASIC_SERC_COST
+ numOfPremChannel * RES_COST_PREM_CHANNEL;

cout << "Account number: "
<< accountNumber << endl;
cout << "Amount due: $" << amountDue << endl;
break;

case 'b':
case 'B':
cout << "Enter the number of basic "
<< "service connections: ";
cin >> numOfBasicServConn;
cout << endl;

cout << "Enter the number"
<< " of premiun channels: ";
cin >> numOfPremChannel;
cout << endl;

if (numOfBasicServConn <= 10)
amountDue = BUS_BILL_PROC_FEES + BUS_BASIC_CONN_COST
+ numOfPremChannel * BUS_COST_PREM_CHANNEL;

else
amountDue = BUS_BILL_PROC_FEES + BUS_BASIC_SERV_COST
+ (numOfBasicServConn - 10) * BUS_BASIC_CONN_COST + numOfPremChannel * BUS_COST_PREM_CHANNEL;

cout << "Amount number: "
<< accountNumber << endl;
cout << "Amount due: $" << amountDue << endl;
break;

default:
cout << "Invalid customer type. " << endl;
}
return 0;
}
Re: A Thread For C++ Programs by Tim1212(m): 9:41am On Aug 20, 2020
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
int numOfItemsBought;
double shippingCharges;

cout << fixed << showpoint << setprecision(2);

cout << "A program to compute the shippping charge of an Item "
<< endl;

cout << "Enter quantity of item bought: ";
cin >> numOfItemsBought;
cout << endl;



if (numOfItemsBought < 5)
shippingCharges = 7.00 * numOfItemsBought;

else if ( 5 <= numOfItemsBought && numOfItemsBought < 10)
shippingCharges = 3.00 * numOfItemsBought;
else if ( numOfItemsBought >= 10)
shippingCharges = 0.0;

cout << "Shipping charges = $" << shippingCharges << endl << endl;

return 0;
}
Re: A Thread For C++ Programs by Tim1212(m): 9:42am On Aug 20, 2020
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

int main()
{
string name;
int numOfVolunteers;
int numOfBoxesSold;
int totalNumOfBoxesSold;
int counter;
double costOfOneBox;

cout << fixed << showpoint << setprecision(2);

cout << "Enter the number of volunteers: ";
cin >> numOfVolunteers;
cout << endl;

totalNumOfBoxesSold = 0;
counter = 0;

while (counter < numOfVolunteers)
{
cout << "Enter the volunteer's name and the number "
<< "of boxes sold: ";
cin >> name >> numOfBoxesSold;

cout << endl;

totalNumOfBoxesSold = totalNumOfBoxesSold + numOfBoxesSold;
counter++;

}

cout << "The total number of boxes sold: " << totalNumOfBoxesSold << endl;

cout << "Enter the cost of one box: ";
cin >> costOfOneBox;
cout << endl;

cout << "The total money made by selling "
<< "cookies: $" << totalNumOfBoxesSold * costOfOneBox << endl;

if (counter != 0)
cout << " The average number of boxes sold "
<< "by each volunteer: " << totalNumOfBoxesSold / counter << endl;
else
cout << "No output" << endl;

return 0;
}
Re: A Thread For C++ Programs by Tim1212(m): 9:43am On Aug 20, 2020
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

const string SENTINEL = "-1";

int main()
{
int numOfBoxesSold, totalNumOfBoxesSold, numOfVolunteers;
string name;
double costOfBoxesSold;

cout << fixed << showpoint << setprecision(2);

cout << "Enter each volunteer's name and number of boxes sold "
<< endl
<< "by each volunteer, ending with -1" << endl;

totalNumOfBoxesSold = 0;
numOfVolunteers = 0;

cin >> name;

while (name != SENTINEL)
{
cin >> numOfBoxesSold;
totalNumOfBoxesSold = totalNumOfBoxesSold + numOfBoxesSold;

numOfVolunteers++;
cin >> name;
}

cout << endl;

cout << "The total number of boxes sold: " << totalNumOfBoxesSold << endl;

cout << "Enter the cost of one box: ";
cin >> costOfBoxesSold;
cout << endl;

cout << "The total number of money made by selling cookies: $"
<< totalNumOfBoxesSold / numOfVolunteers << endl;

if (numOfVolunteers != 0)
cout << "The average number of boxes sold by each volunteer: "
<< totalNumOfBoxesSold / numOfVolunteers
<< endl;
else
cout << "No output. " << endl;

return 0;
}
Re: A Thread For C++ Programs by Tim1212(m): 9:46am On Aug 20, 2020
#include <iostream>

using namespace std;

int main()
{

int num, digit;
char letter;


cout << "Program to convert uppercase letter to "
<< "their corresponding telephone digits."
<< endl;

cout << "To stop the program enter #. " << endl;

cout << "Enter an uppercase letter: ";
cin >> letter;
cout << endl;

while (letter != '#')
{
cout << "Letter: " << letter;
cout << ", Corresponding telephone digit: ";

num = static_cast<int>(letter) - static_cast<int>('A');

if (0 <= num && num < 26)
{
digit = (num / 3) + 2;

if (((num / 3 == 6) || (num / 3 == 7)) && (num % 3 == 0))
digit = digit - 1;

if (digit > 9)
digit = 9;

cout << digit << endl;
}
else
cout << "Invalid input. " << endl;

cout << "\nEnter another uppercase "
<< "letter to find its corresponding "
<< "telephone digit." << endl;
cout << "To stop the program enter #." << endl;


cout << "Enter a letter: ";
cin >> letter;
cout << endl;
}

return 0;
}
Re: A Thread For C++ Programs by Tim1212(m): 9:47am On Aug 20, 2020
#include <iostream>
#include <cstdlib>
#include <ctime>


using namespace std;

int main()

{
int num;
bool isGuessed;
int guess;


srand(time(0));
num = rand() % 100;

isGuessed = false;

while (!isGuessed)
{
cout << "Enter an integer greater than or equal to 0 "
<< "and less than 100: ";

cin >> guess;
cout << endl;

if (guess == num)
{
cout << "You guessed the correct number. " << endl;
isGuessed = true;
}
else if (guess < num )
cout << "Your guess is lower than the number.\n Guess again!"
<< endl;
else
cout << "Your guess is higher than "
<< "the number.\n Guess again!"
<< endl;



}


return 0;
}
Re: A Thread For C++ Programs by Nobody: 9:48am On Aug 20, 2020
Is everything alright?
Re: A Thread For C++ Programs by Tim1212(m): 9:51am On Aug 20, 2020
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>

using namespace std;

int main()
{

double testScore;
double average;
double sum = 0;
int count = 0;
char grade;

string firstName;
string secondName;

ifstream inFile;
ofstream outFile;

inFile.open("text.dat"wink;

if (!inFile)
{
cout << "Cannot open input file. "
<< "program terminated " << endl;

return 1;
}

outFile.open("avgtxt.out"wink;

outFile << fixed << showpoint << setprecision(2);

cout << "Data processing " << endl;

inFile >> firstName >> secondName;
inFile >> testScore;

while (inFile)
{

sum = sum + testScore;
count++;

switch (static_cast<int>(testScore / 10))
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
grade = 'F';
break;
case 6:
grade = 'D';
break;
case 7:
grade = 'C';
break;
case 8:
grade = 'B';
break;
case 9:
case 10:
grade = 'A';
break;
default:
cout << "Invalid score." << endl;

}
outFile << left << setw(12) << firstName
<< setw(12) << secondName
<< right << setw(4) << testScore
<< setw(2) << grade << endl;

inFile >> firstName >> secondName;
inFile >> testScore;
}



if (count != 0)
outFile << "Clasee Average: " << sum / count
<< endl;
else
outFile << "No data." << endl;

inFile.close();
outFile.close();

return 0;
}

input

Steve Gile 17.98
Rita Johnson 91.8
Randy Brown 85.5
Seema Arora 76.5
Samir Mann 73
Samantha McCoy 88.3

output

Steve Gile 17.98 F
Rita Johnson 91.80 A
Randy Brown 85.50 B
Seema Arora 76.50 C
Samir Mann 73.00 C
Samantha McCoy 88.30 B
Clasee Average: 72.18
Re: A Thread For C++ Programs by Tim1212(m): 9:54am On Aug 20, 2020
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>

using namespace std;

const double MINIMUM_BALANCE = 1000.00;
const double SERVICE_CHARGE = 25.00;

int main()

{
string name;
int acountNumber;
double beginningBalance = 0.0;
double accountBalance = 0.0;
double amountDeposited = 0.0;
int numberOfDeposits = 0;
double amountWithdrawn = 0.0;
int numberOfWithdrawn = 0;
double transactionAmount = 0.0;
char transactionCode;
double interestPaid = 0.0;

bool isServiceCharge = false;

ifstream inFile;
ofstream outFile;


inFile.open("acc.dat"wink;

if (!inFile)
{
cout << "Cannot open the file. \nProgram terminated. "
<< endl;

return 0;
}

outFile.open("actfile.out"wink;

outFile << fixed << showpoint << setprecision(2);

cout << "Data processing...." << endl;

inFile >> name >> acountNumber >> beginningBalance;

accountBalance = beginningBalance;

inFile >> transactionCode >> transactionAmount;


while (inFile)
{
switch (transactionCode)
{
case 'D':
case 'd':
accountBalance = accountBalance + transactionAmount;
amountDeposited = amountDeposited + transactionAmount;
numberOfDeposits++;
break;
case 'I':
case 'i':
accountBalance = accountBalance + transactionAmount;
interestPaid = interestPaid + transactionAmount;
break;
case 'W':
case 'w':
accountBalance = accountBalance - transactionAmount;
amountWithdrawn = amountWithdrawn + transactionAmount;
numberOfWithdrawn++;

if ((accountBalance < MINIMUM_BALANCE) && (!isServiceCharge))
{
accountBalance = accountBalance - SERVICE_CHARGE;

isServiceCharge = true;
}
if ((accountBalance < transactionAmount) || (amountWithdrawn > accountBalance))
{
accountBalance = 0.0;
amountWithdrawn = 0.0;
numberOfWithdrawn = 0;
cout << "Insufficient fund...." << endl;
}




break;

default:
cout << "Invalid transaction code " << endl;
}



inFile >> transactionCode >> transactionAmount;
}

outFile << "Account Name: " << name << endl;
outFile << "Beginning Balance: $" << beginningBalance << endl;
outFile << "Ending Balance: $" << accountBalance <<endl;
outFile << "Interest Paid: $" << interestPaid <<endl << endl;

outFile << "Amount Deposited: $" << amountDeposited << endl;
outFile << "Number of Deposits: " << numberOfDeposits << endl << endl;

outFile << "Amount Withdrawn: $" << amountWithdrawn << endl;
outFile << "Number of withdrawn: " << numberOfWithdrawn << endl << endl;

outFile << "Thank you for banking with us!" << endl;

if (isServiceCharge)
outFile << "Service Charge: $" << SERVICE_CHARGE << endl;

inFile.close();
outFile.close();

return 0;
}


Input
Tim 467456 23750.45
W 259.00
d 1200.00
W 75.00
D 589.55
I 249
W 345
w 32.89
d 200
d 7000
w 804
d 9000.65
w 100000


Output

Account Name: Tim
Beginning Balance: $23750.45
Ending Balance: $0.00
Interest Paid: $249.00

Amount Deposited: $17990.20
Number of Deposits: 5

Amount Withdrawn: $0.00
Number of withdrawn: 0

Thank you for banking with us!
Service Charge: $25.00
Re: A Thread For C++ Programs by Tim1212(m): 9:56am On Aug 20, 2020
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{

int guess;
int num;
int noOfGuessess = 0;
int chances = 5;
bool isGuessed = false;

srand(time(0));
num = rand() % 100;

while ((noOfGuessess < 5) && (!isGuessed))
{


cout << "Enter an integer greater than or equal to 0 and "
<< "\nless than 100: ";

cin >> guess;
cout << endl;
noOfGuessess++;
chances--;
if (guess > 100)
{


cout << "Invalid guess! " << endl;
isGuessed = true;

}

else if (guess == num)
{
cout << "WInner!. You guessed the correct number. "
<< endl;
isGuessed = true;
}
else if (guess < num)
cout << "Your guess is lower than the number.\n"
<< "Guess again!" << endl;
else
cout << "your guess is higher than the number.\n"
<< "Guess again!" << endl;


cout << "you have: " << chances << " chances! " << endl;
}


if (!isGuessed)
cout << "you loss!. The correct number is " << num << endl;

return 0;
}
Re: A Thread For C++ Programs by Tim1212(m): 9:57am On Aug 20, 2020
#include <iostream>

using namespace std;
typedef double d;
const d PI = 3.14;

int main()
{
d radius, circumference, area;
cout << "Welcome to the circle creator." << endl;
cout << "What would like the raduis of the circle be: ";
cin >> radius;
cout << endl;

area = PI * radius * radius;
circumference = PI * (radius * 2);

cout << "The are of the circle is: " << area << endl << endl;
cout << "The circumference of the circle is: " << circumference << endl << endl;
cout << "Thank you for playing the circle game! " << endl;

return 0;
}

1 Like

Re: A Thread For C++ Programs by Tim1212(m): 9:58am On Aug 20, 2020
#include <iostream>

using namespace std;

bool main()
{
int previous1, previous2, current , counter, nthFibonacci;
double y;


cout << "Enter the first two Fibonacci "
<< "numbers: ";
cin >> previous1 >> previous2;
cout << endl;

cout << "The first two Fibonaccci number are "
<< previous1 << " and " << previous2
<< endl;
cout << "Enter the position of the desired "
<< " Fibonacci number: ";
cin >> nthFibonacci;
cout << endl;

if (nthFibonacci == 1)
current = previous1;
else if (nthFibonacci == 2)
current = previous2;
else
{
counter = 3;

while (counter <= nthFibonacci)
{

current = previous2 + previous1;
previous1 = previous2;
previous2 = current;
counter++;
}
}

cout << "The Fibonacci at position "
<< nthFibonacci << " is " << current
<< endl;
return false;
}

1 Like

Re: A Thread For C++ Programs by Tim1212(m): 10:00am On Aug 20, 2020
#include <iostream>

using namespace std;

int main()
{
int counter;
int sum = 0;
int n;

cout << "Enter the number of positve even "
"integers to be added: ";
cin >> n;
cout << endl;

for (counter = 2; counter <= n; counter = counter + 2)
sum = sum + counter;

cout << "The sum of the first "
<< "positive integer is " << sum
<< endl;
return 0;
}

1 Like

Re: A Thread For C++ Programs by Tim1212(m): 10:01am On Aug 20, 2020
#include <iostream>


using namespace std;



int main()
{
int counter;
int number, N;
int odds = 0;
int evens = 0;
int zeros = 0;

cout << "Please enter number of integers: "
<< "\n(positive, negative, or zeros). ";
cin >> N;
cout << endl;


cout << "The number you entered are: " << endl;

for (counter = 1; counter <= N; counter++)
{
cin >> number;
cout << number << " ";

switch (number % 2)
{
case 0:
evens++;
if (number == 0)
zeros++;
break;
case 1:
case -1:
odds++;
}
}

cout << endl;

cout << "There are " << evens << " evens, "
<< "which includes " << zeros << " zeros. "
<< endl;
cout << "The number of odds is: " << odds << endl;

return 0;
}

1 Like

(1) (2) (Reply)

Check Out These Beautiful Website I Designed Within 2 Days / Please Recommend A Good And Comfortable Work Chair / Posts Cannot Be Edited Again?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 101
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.