Tuesday, 15 January 2019

Problem No#15 of Chapter 7 "Arrays" out of the book of "Getting Started with C++" by Tony Gaddis | Asad Ali


Problem No#15 of Chapter 7 "Arrays" out of the book of "Getting Started with C++" by Tony Gaddis


/*
Name: Asad Ali
Copyright: All Rights Reserved by JanGoO Group of Companies
Author: Tony Gaddies
Date: 15/01/19 00:12
Description: This program basically comparies user input
lottery number to the computer generated lottery ticket
number after comparing each digit, it show out put of
number of digits same in computer generated lottery
number and user entered lottery number.
Then there are some pre-fiexed prizes in the program:
If
1. One digit     =  prize of Rs.100
2. Two digits    =  prize of Rs.200
3. Three digits  =  prize of Rs.300
4. Four digits   =  prize of Rs. 400
5. Five digits   =  prize of Rs. 500

and program will output one of these prizes accourding to
the number of digits matched.

//// Computer Lottery Digits <compure with> User Lottery Digits
*/

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{
const int SIZE = 5;
int lottery_arr[SIZE];
int user_arr[SIZE];
int num_of_same_digits = 0;

srand(time(NULL));

for ( int i = 0; i < 5; i++ )
{
lottery_arr[i] = rand() % 10;
}

cout << ".-----------------------------------------------.\n";
cout << "|\t \t \t \t \t \t|" << endl;
cout << "|  Ticket has 5 digits for example : ";
for ( int i = 0; i < 5; i++ )
{
cout << lottery_arr[i] << " ";
}
cout << " |";

cout << "\n|\t \t \t \t \t \t|" << endl;
cout << "|-----------------------------------------------|";
cout << endl;

cout << "|  Enter your lottery ticket digits one by one  |" << endl;
cout << "'-----------------------------------------------'\nINPUT\\>\n";

for ( int i = 0; i < 5; i++ )
{
cin >> user_arr[i];
}

cout << endl;
cout << ".-----------------------------------------------.\n";

for ( int i = 0; i < 5; i++ )
{
if ( lottery_arr[i] == user_arr[i] )
{
num_of_same_digits = num_of_same_digits + 1;
}
}

cout << "|  Winner Lottery ticket digits are : ";
for ( int i = 0; i < 5; i++ )
{
cout << lottery_arr[i] << " ";
}

cout << "|" << endl;
cout << "|  User Lottery ticket digits a r e : ";
for ( int i = 0; i < 5; i++ )
{
cout << user_arr[i] << " ";
}

cout << "|" << endl;
cout << "|-----------------------------------------------|";

cout << "\n|\t \t \t \t \t \t|" << endl;
cout << "|          Number of digits matched :" << num_of_same_digits << "          |";

cout << "\n|\t \t \t \t \t \t|" << endl;
cout << "|-----------------------------------------------|";
cout << "\n|\t \t \t \t \t \t|" << endl;

switch(num_of_same_digits)
{
case 1: cout << "|              OH! You won Rs.100               |\n|           Only one digit matched!             |";
cout << "\n|\t \t \t \t \t \t|" << endl;
cout << "'-----------------------------------------------'\n";
break;
case 2: cout << "|              OH! You won Rs.200               |\n|           Only two digit matched!             |";
cout << "\n|\t \t \t \t \t \t|" << endl;
cout << "'-----------------------------------------------'\n";
break;
case 3: cout << "|              OH! You won Rs.300               |\n|           Only three digit matched!           |";
cout << "\n|\t \t \t \t \t \t|" << endl;
cout << "'-----------------------------------------------'\n";
break;
case 4: cout << "|               OH! You won Rs.400              |\n|            Only four digit matched!           |";
cout << "\n|\t \t \t \t \t \t|" << endl;
cout << "'-----------------------------------------------'\n";
break;
case 5: cout << "| Congrats!  You won grand prize of Rs.500 ONLY |\n|     A l l   d i g i t s   m a t c h e d !     |";
cout << "\n|\t \t \t \t \t \t|" << endl;
cout << "'-----------------------------------------------'\n";
break;
default: cout << "|       Sorry! You lose : TRY AGAIN LETER       |";
cout << "\n|\t \t \t \t \t \t|";
cout << "\n'-----------------------------------------------'\n";
break;
}


}

/// Code by Asad Ali and officially posted on padacode.blogspot.com

Please help me improve my work by letting me know about mistakes (if any) I mad in the project given above, by commenting on the particular post.
Share:

Problem No#13 of Chapter 7 "Arrays" out of the book of "Getting Started with C++" by Tony Gaddis | Asad Ali


Problem No#13 of Chapter 7 "Arrays" out of the book of "Getting Started with C++" by Tony Gaddis




/*
Name: Grade Book
Copyright: JanGoO
Author: Asad Ali
Date: 15/01/19 15:37
Description: This program will take input from the user for
the name of each 5 students and then marks obtained by each
of them in each of the four subjects and then program will
operate on these few informations and show the sum, average
percentage and grade of the each student in the exams.
*/

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
string student_name[5];
char grades[5] = {'A', 'B', 'C', 'D', 'F'};
int student_marks[5][4];
double sum[5] = {0, 0, 0, 0, 0};
double ave[5] = {0, 0, 0, 0, 0};
double per[5] = {0, 0, 0, 0, 0};

for ( int i = 0; i < 5; i++ )
{
cout << "Name of " << i+1 << " student : ";
cin >> student_name[i];
for ( int j = 0; j < 4; j++ )
{
cout << "Marks of " << student_name[i] << " in subject " << j+1 << " : ";
cin >> student_marks[i][j];
if ( student_marks[i][j] >= 1 && student_marks[i][j] <= 100 )
{
sum[i] = sum[i] + student_marks[i][j];
}
else
{
cout << "Error! Please Enter marks out 100.";
return 0;
}
}
ave[i] = sum[i] / 4;
per[i] = ( sum[i] / 400 ) * 100;
system("cls");
}
cout << endl;
cout << "Name";
for ( int i = 0; i < 4; i++ )
{
cout << "\t Sub1" << i;
}
cout << "\t S  u  m ";
cout << "\t\t averg";
cout << "\t per %";
cout << "\t Grade";
cout << endl;
for ( int i = 0; i < 5; i++ )
{
for ( int j = 0; j < 1; j++ )
{
cout << student_name[i];
}
for ( int j = 0; j < 4; j++ )
{
cout << "\t " << "  " << student_marks[i][j];
}
for ( int j = 0; j < 1; j++ )
{
cout << "\t " << "  " << setprecision(1) << fixed << setw(4) << sum[i];
}
for ( int j = 0; j < 1; j++ )
{
cout << "\t " << "  " << setprecision(1) << fixed << setw(4) << ave[i];
}
for ( int j = 0; j < 1; j++ )
{
cout << "\t " << "  " << setprecision(1) << fixed << setw(4) << per[i];
}
for ( int j = 0; j < 1; j++ )
{
//// cout << "\t " << "  " << grades[i];
if ( per[i] >= 90 && per[i] <= 100 )
{
cout << "\t " << "  " << grades[0];
}
else if ( per[i] >= 80 && per[i] <= 89 )
{
cout << "\t " << "  " << grades[1];
}
else if ( per[i] >= 70 && per[i] <= 79 )
{
cout << "\t " << "  " << grades[2];
}
else if ( per[i] >= 60 && per[i] <= 69 )
{
cout << "\t " << "  " << grades[3];
}
else if ( per[i] >= 0 && per[i] <= 59 )
{
cout << "\t " << "  " << grades[4];
}
else
{
/// Error! Statement
cout << "ERROR!";
}
}
cout << endl;
}
}

/// Code by Asad Ali and officially posted on padacode.blogspot.com

Please help me improve my work by letting me know about mistakes (if any) I mad in the project given above, by commenting on the particular post.
Share:

Problem No#11 of Chapter 7 "Arrays" out of the book of "Getting Started with C++" by Tony Gaddis | Asad Ali


Problem No#11 of Chapter 7 "Arrays" out of the book of "Getting Started with C++" by Tony Gaddis


/// Problem Set 3. Mobile Service Provider - Part 2

#include <iostream>
using namespace std;
int main()
{
char correct_ans[20] = {'B', 'D', 'A', 'A', 'C', 'A', 'B', 'A', 'C', 'D', 'B', 'C', 'D', 'A', 'D', 'C', 'C', 'B', 'D', 'A'};
char user_ans[20];
int n_correct_ans = 0, n_wrong_ans = 0;

cout << "Enter the answer for each of the questions:- " << endl;
for ( int i = 0; i < 20; i++ )
{
cout << "Question NO # " << i + 1 << endl;
for ( int j = 0; j < 1; j++ )
{
cout << "Answer : ";
cin >> user_ans[i];
if ( cin.fail() )
{
return 0;
}
}
}

for ( int i = 0; i < 20; i++ )
{
if ( correct_ans[i] == user_ans[i] )
{
n_correct_ans = n_correct_ans + 1;
}
}

n_wrong_ans = 20 - n_correct_ans;

cout << "Number of correctly answered questions : " << n_correct_ans << endl;
cout << "Number of wrongly answored questions : " << n_wrong_ans << endl;
}

/// Code by Asad Ali and officially posted on padacode.blogspot.com

Please help me improve my work by letting me know about mistakes (if any) I mad in the project given above, by commenting on the particular post.
Share:

Friday, 4 January 2019

Simple JanGoO Portfolio Template ( HTML, CSS ) | Asad Ali


Click the button bellow to download the JanGoO Simple Portfolio Template:



Share:

Sunday, 9 December 2018

Starting out with C++; Early Objects 8th Edition | PDF | Original | Tony Gaddis | Judy Walters | Godfrey Muganda | Uploaded by Asad Ali


Starting out with C++; Early Objects 8th Edition .pdf

File Name : Starting Out With C Early Objects 8th Edition .pdf

Size: 16.8 MB

Edition:8th

Author: Tony Gaddis, Judy Walters, Godfrey Muganda

Publisher:Pearson

Release Date:March 2013



Download and Enjoy For Free!

Contents

Preface xv
CHAPTER 1 Introduction to Computers and Programming 1
CHAPTER 2 Introduction to C++ 27
CHAPTER 3 Expressions and Interactivity 77
CHAPTER 4 Making Decisions 155
CHAPTER 5 Looping 243
CHAPTER 6 Functions 323
CHAPTER 7 Introduction to Classes and Objects 407
CHAPTER 8 Arrays 503
CHAPTER 9 Searching, Sorting, and Algorithm Analysis 595
CHAPTER 10 Pointers 637
CHAPTER 11 More About Classes and Object-Oriented Programming 695
CHAPTER 12 More on C-Strings and the string Class 789
CHAPTER 13 Advanced File and I/O Operations 837
CHAPTER 14 Recursion 899
CHAPTER 15 Polymorphism and Virtual Functions 933
CHAPTER 16 Exceptions, Templates, and the Standard Template Library (STL) 971
CHAPTER 17 Linked Lists 1021
CHAPTER 18 Stacks and Queues 1069
CHAPTER 19 Binary Trees 1109
Appendix A: The ASCII Character Set 1139
Appendix B: Operator Precedence and Associativity 1143
Appendix C: Answers to Checkpoints 1145
Appendix D: Answers to
Share:

Monday, 3 December 2018

Unlimited Positive Number Inputs | C++ | Asad Ali


Unlimited Positive Inputs


Write a program that will ask the user to input n positive numbers. The program will terminate if one of those number is not positive.

#include <iostream>
using namespace std;
int main()
{
long int num = 0;

while( num >= 0 )
{
cout << "Enter a postive number: ";
cin >> num;
}

return 0;
}

Please help me improve my work by letting me know about mistakes (if any) I mad in the project given above, by commenting on the particular post.
Share:

Friday, 30 November 2018

Problem Set 3. Mobile Service Provider - Part 3 | Asad Ali


Problem Set 3. Mobile Service Provider - Part 3


/// Problem Set 3. Mobile Service Provider - Part 2

#include <iostream>
#include <string>
using namespace std;
int main()
{
string month;
char choice;
int mins, extramins;
double extraCharges, dueAmount, saved_B, saved_C;
cout << "\t\t\t\tMobile Service Provider" << endl;
cout << "--------------------------------------------------------------------------------------------------" << endl;
cout << "Package A: For $39.99 per month 450 minutes are provided. Additional minutes are $0.45 per minute." << endl;
cout << "Package B: For $59.99 per month 900 minutes are provided. Additional minutes are $0.40 per minute." << endl;
cout << "Package C: For $69.99 per month unlimited minutes provided." << endl;
cout << "--------------------------------------------------------------------------------------------------" << endl;
cout << "Choose a package out of A, B and C : ";
cin >> choice;
switch ( choice )
{
case 'A':
case 'a':
cout << "How many minuts you used : ";
cin >> mins;
cout << "Wright the name of the month : ";
cin >> month;
if ( month == "January" || month == "March" || month == "May" || month == "July" || month == "August" || month == "October" || month == "December" )
{
if ( mins <= 744 * 60 )
{
if ( mins <= 450 && mins > 0 )
{
cout << "Total amount due : $39.99" << endl;
}
else if ( mins > 450 && mins <= 900 )
{
extramins = mins - 450;
extraCharges = extramins * 0.45;
dueAmount = 39.99 + extraCharges;
cout << "Total amount due : $" << dueAmount << endl;
saved_B = dueAmount - 59.99;
if ( saved_B > 0 )
{
cout << "You would saved about $" << saved_B << " if you had choosed Package B." << endl;
}
}
else if ( mins > 900 )
{
extramins = mins - 450;
extraCharges = extramins * 0.45;
dueAmount = 39.99 + extraCharges;
cout << "Total amount due : $" << dueAmount << endl;
saved_C = dueAmount - 69.99;
if ( saved_C > 0 )
{
cout << "You would saved about $" << saved_C << " if you had choosed Package C." << endl;
}
}
else
{
cout << "ERROR!" << endl;
}
}
else
{
cout << "You have entered impossible number of minuts. January, March, May, July, August, October, December have only " << 744 * 60 << " minuts at most." << endl;
}
}
if ( month == "April" || month == "June" || month == "September" || month == "November" )
{
if ( mins <= 720 * 60 )
{
if ( mins <= 450 && mins > 0 )
{
cout << "Total amount due : $39.99" << endl;
}
else if ( mins > 450 && mins <= 900 )
{
extramins = mins - 450;
extraCharges = extramins * 0.45;
dueAmount = 39.99 + extraCharges;
cout << "Total amount due : $" << dueAmount << endl;
saved_B = dueAmount - 59.99;
if ( saved_B > 0 )
{
cout << "You would saved about $" << saved_B << " if you had choosed Package B." << endl;
}
}
else if ( mins > 900 )
{
extramins = mins - 450;
extraCharges = extramins * 0.45;
dueAmount = 39.99 + extraCharges;
cout << "Total amount due : $" << dueAmount << endl;
saved_C = dueAmount - 69.99;
if ( saved_C > 0 )
{
cout << "You would saved about $" << saved_C << " if you had choosed Package C." << endl;
}
}
else
{
cout << "ERROR!" << endl;
}
}
else
{
cout << "You have entered impossible number of minuts. April, June, September, November December have only " << 744 * 60 << " minuts at most." << endl;
}
}
if ( month == "February" )
{
if ( mins <= 672 * 60 )
{
if ( mins <= 450 && mins > 0 )
{
cout << "Total amount due : $39.99" << endl;
}
else if ( mins > 450 && mins <= 900 )
{
extramins = mins - 450;
extraCharges = extramins * 0.45;
dueAmount = 39.99 + extraCharges;
cout << "Total amount due : $" << dueAmount << endl;
saved_B = dueAmount - 59.99;
if ( saved_B > 0 )
{
cout << "You would saved about $" << saved_B << " if you had choosed Package B." << endl;
}
}
else if ( mins > 900 )
{
extramins = mins - 450;
extraCharges = extramins * 0.45;
dueAmount = 39.99 + extraCharges;
cout << "Total amount due : $" << dueAmount << endl;
saved_C = dueAmount - 69.99;
if ( saved_C > 0 )
{
cout << "You would saved about $" << saved_C << " if you had choosed Package C." << endl;
}
}
else
{
cout << "ERROR!" << endl;
}
}
else
{
cout << "You have entered impossible number of minuts. February has only " << 744 * 60 << " minuts at most." << endl;
}
}
break;
case 'B':
case 'b':
cout << "How many minuts you used : ";
cin >> mins;
cout << "Wright the name of the month : ";
cin >> month;
if ( month == "January" || month == "March" || month == "May" || month == "July" || month == "August" || month == "October" || month == "December" )
{
if ( mins <= 744 * 60 )
{
if ( mins > 0 )
{
if ( mins <= 900 && mins > 450 )
{
cout << "Total amount due : $59.99" << endl;
}
else if ( mins > 900 )
{
extramins = mins - 900;
extraCharges = extramins * 0.40;
dueAmount = 59.99 + extraCharges;
cout << "Total amount due : $" << dueAmount << endl;
saved_C = dueAmount - 69.99;
if ( saved_C > 0 )
{
cout << "You would saved about $" << saved_C << " if you had choosed Package C." << endl;
}
else
{
// display nothing
}
}
else if ( mins <= 450 && mins > 0 )
{
dueAmount = 59.99 + extraCharges;
cout << "You would saved about $" << dueAmount - 39.99 << " if you had choosed Package A." << endl;
}
}
else
{
cout << "ERROR!" << endl;
}
}
else
{
cout << "You have entered impossible number of minuts. January, March, May, July, August, October, December have only " << 744 * 60 << " minuts at most." << endl;
}
}
if ( month == "April" || month == "June" || month == "September" || month == "November" )
{
if ( mins <= 720 * 60 )
{
if ( mins > 0 )
{
if ( mins <= 900 && mins > 450 )
{
cout << "Total amount due : $59.99" << endl;
}
else if ( mins > 900 )
{
extramins = mins - 900;
extraCharges = extramins * 0.40;
dueAmount = 59.99 + extraCharges;
cout << "Total amount due : $" << dueAmount << endl;
saved_C = dueAmount - 69.99;
if ( saved_C > 0 )
{
cout << "You would saved about $" << saved_C << " if you had choosed Package C." << endl;
}
else
{
// display nothing
}
}
else if ( mins <= 450 && mins > 0 )
{
dueAmount = 59.99 + extraCharges;
cout << "You would saved about $" << dueAmount - 39.99 << " if you had choosed Package A." << endl;
}
}
else
{
cout << "ERROR!" << endl;
}
}
else
{
cout << "You have entered impossible number of minuts. April, June, September, November December have only " << 744 * 60 << " minuts at most." << endl;
}
}
if ( month == "February" )
{
if ( mins <= 672 * 60 )
{
if ( mins > 0 )
{
if ( mins <= 900 && mins > 450 )
{
cout << "Total amount due : $59.99" << endl;
}
else if ( mins > 900 )
{
extramins = mins - 900;
extraCharges = extramins * 0.40;
dueAmount = 59.99 + extraCharges;
cout << "Total amount due : $" << dueAmount << endl;
saved_C = dueAmount - 69.99;
if ( saved_C > 0 )
{
cout << "You would saved about $" << saved_C << " if you had choosed Package C." << endl;
}
else
{
// display nothing
}
}
else if ( mins <= 450 && mins > 0 )
{
dueAmount = 59.99 + extraCharges;
cout << "You would saved about $" << dueAmount - 39.99 << " if you had choosed Package A." << endl;
}
}
else
{
cout << "ERROR!" << endl;
}
}
else
{
cout << "You have entered impossible number of minuts. February has only " << 744 * 60 << " minuts at most." << endl;
}
}
break;
case 'C':
case 'c':
cout << "How many minuts you used : ";
cin >> mins;
cout << "Wright the name of the month : ";
cin >> month;
if ( month == "January" || month == "March" || month == "May" || month == "July" || month == "August" || month == "October" || month == "December" )
{
if ( mins <= 744 * 60 )
{
if ( mins > 0 )
{
if ( mins > 450 && mins <= 900 )
{
cout << "You should choose Package B. In this way you would save about $10." << endl;

}
else if ( mins <= 450 )
{
cout << "You should choose Package A. In this way you would save about $30." << endl;
}
else
{
cout << "Total amount due : $69.99" << endl;
}
}
else
{
cout << "ERROR!" << endl;
}
}
else
{
cout << "You have entered impossible number of minuts. January, March, May, July, August, October, December have only " << 744 * 60 << " minuts at most." << endl;
}
}
if ( month == "April" || month == "June" || month == "September" || month == "November" )
{
if ( mins <= 720 * 60 )
{
if ( mins > 0 )
{
if ( mins > 450 && mins <= 900 )
{
cout << "You should choose Package B. In this way you would save about $10." << endl;

}
else if ( mins <= 450 )
{
cout << "You should choose Package A. In this way you would save about $30." << endl;
}
else
{
cout << "Total amount due : $69.99" << endl;
}
}
else
{
cout << "ERROR!" << endl;
}
}
else
{
cout << "You have entered impossible number of minuts. April, June, September, November December have only " << 744 * 60 << " minuts at most." << endl;
}
}
if ( month == "February" )
{
if ( mins <= 672 * 60 )
{
if ( mins > 0 )
{
if ( mins > 450 && mins <= 900 )
{
cout << "You should choose Package B. In this way you would save about $10." << endl;

}
else if ( mins <= 450 )
{
cout << "You should choose Package A. In this way you would save about $30." << endl;
}
else
{
cout << "Total amount due : $69.99" << endl;
}
}
else
{
cout << "ERROR!" << endl;
}
}
else
{
cout << "You have entered impossible number of minuts. February has only " << 744 * 60 << " minuts at most." << endl;
}
}
break;
default:
cout << "ERROR!" << endl;
break;
}
return 0;
}

/// Code by Asad Ali and officially posted on padacode.blogspot.com

Please help me improve my work by letting me know about mistakes (if any) I mad in the project given above, by commenting on the particular post.
Share:

padacode.blogspot.com

Powered by Blogger.