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:

padacode.blogspot.com

Powered by Blogger.