arrow
arrow

PF-PUCIT(NEW-CAMPUS)

ASSIGNMENT 03:

Sample:Random_Numbers Between 1---9


                            
                                #include<iostream>
                                #include<cstdlib>
                                #include<ctime>
                                using namespace std;
                                    int main()
                                    { int x=time(0);
                                        int random;
                                        srand(x);
                                        random=rand()%10+1;
                                        cout<<random<<endl;
                                        return 0;}
                            
                        

To see the assignment in pdf form


Practice these questions by yourself then see codecheets😂


------------------------------------------

DOWnload PDF HERE

Task 1.Software Sales A software company sells a package that retails for $99. Quantity discounts are given
according to the following table. Quantity
Discount
10–19 20%
20–49 30%
50–99 40%
100 or more 50%
Write a program that asks for the number of units sold and computes the total cost of
the purchase.
Input Validation: Make sure the number of units is greater than 0.


                        
                            #include <iostream>
                                using namespace std;
                                int main()
                                {
                                
                                    const int retail_price = 99;
                                    int num;
                                    int cost;
                                    float discount;
                                    float purchase;
                                    cout << "_____________________________________________________" << endl;
                                    cout << "-------------------Software Sales--------------------" << endl;
                                    cout << "_____________________________________________________" << endl;
                                    cout << "The retail price = " << retail_price << endl;
                                    cout << "Enter the number of units sold:" << endl;
                                    cin >> num;
                                    if (num > 0)
                                    {
                                        if (num >= 10)
                                        {
                                            if (num < 20)
                                            {
                                                cost = retail_price * num;
                                                discount = (cost * 0.2);
                                                purchase = cost - discount;
                                                cout << "The total cost of the purchase with 20% discount = $" << purchase << endl;
                                            }
                                        }
                                        if (num >= 20)
                                        {
                                            if (num < 50)
                                            {
                                                cost = retail_price * num;
                                                discount = (cost * 0.3);
                                                purchase = cost - discount;
                                                cout << "The total cost of the purchase with 30% discount = $" << purchase << endl;
                                            }
                                        }
                                        if (num >= 50)
                                        {
                                            if (num < 99)
                                            {
                                                cost = retail_price * num;
                                                discount = (cost * 0.4);
                                                purchase = cost - discount;
                                                cout << "The total cost of the purchase with 40% discount = $" << purchase << endl;
                                            }
                                        }
                                        if (num >= 100)
                                        {
                                            cost = retail_price * num;
                                            discount = (cost * 0.5);
                                            purchase = cost - discount;
                                            cout << "The total cost of the purchase with 50% discount = $" << purchase << endl;
                                        }
                                    }
                                    // for invalid input
                                    else
                                    {
                                        cout << "Invalid:input!" << endl;
                                        cout << "Please Enter the number greater than zero :" << endl;
                                    }
                                
                                    return 0;
                                }
                        
                    

Task 2. Palindromes) A palindrome is a number or a text phrase that reads the same backward as forward. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and 11611. Write a program that reads in a five-digit integer and determines whether it’s a palindrome. [Hint: Use the division and modulus operators to separate the number into its individual digits


                        
                            #include <iostream>
                                using namespace std;
                                int main()
                                {
                                    // Digits of a number
                                    int num1 = 0;
                                    int rem1 = 0; /*All values are initialize to zero to overwrite the garbage value*/
                                    int rem2 = 0;
                                    int rem3 = 0;
                                    int rem4 = 0;
                                    int rem5 = 0;
                                    cout << "_____________________________________________________" << endl;
                                    cout << "-------------------Palindrome Validation--------------------" << endl;
                                    cout << "_____________________________________________________" << endl;
                                    cout << "Enter the five-digit number:" << endl;
                                    cin >> num1;
                                    // Reminder 5
                                    rem5 = num1 % 10;
                                    // Reminder 4
                                    num1 = num1 / 10;
                                    rem4 = num1 % 10;
                                    // Reminder 3
                                    num1 = num1 / 10;
                                    rem3 = num1 % 10;
                                    // Reminder 2
                                    num1 = num1 / 10;
                                    rem2 = num1 % 10;
                                    // Reminder 1
                                    num1 = num1 / 10;
                                    rem1 = num1 % 10;
                                    // decisoions
                                    if (rem1 == rem5)
                                    {
                                        if (rem2 == rem4)
                                        {
                                            cout << "It is a palindrome number:" << endl;
                                        }
                                    }
                                    else
                                    {
                                        cout << "It is not a palindrome number:" << endl;
                                    }
                                
                                    return 0;
                                }
                        
                    

Task 3. (Printing the Decimal Equivalent of a Binary Number) Input an integer containing only 0s and 1s (i.e., a “binary” integer) and print its decimal equivalent. Use the modulus and division operators to pick off the “binary” number’s digits one at a time from right to left. Much as in the decimal number system, where the rightmost digit has a positional value of 1, the next digit left has a positional value of 10, then 100, then 1000, and so on, in the binary number system the rightmost digit has a positional value of 1, the next digit left has a positional value of 2, then 4, then 8, and so on. Thus the decimal number 234 can be interpreted as2* 100 +3* 10 + 4 * 1. The decimal equivalent of binary 1101 is 1 * 1+0* 2+1* 4+1* 8 or 1 +0+ 4+8, or 13


                        
                            #include<iostream>
                                #include<cmath>
                                using namespace std;
                                int main()
                                {
                                
                                    int binary;
                                    int rem;
                                    int cal;
                                    int n=0;
                                    cout << "_____________________________________________________" << endl;
                                    cout << "-------------(Binary to decimal Calculator)----------" << endl;
                                    cout << "_____________________________________________________" << endl;
                                    cout<<"Enter the number in binary form:"<<endl;
                                    cin>>binary;
                                    //calculations
                                    while(binary!=0)
                                    {
                                        rem=binary%10;
                                        cal+=rem*(pow(2,n));
                                        binary=binary/10;
                                        n++;
                                    }
                                    //Display
                                    cout<<"The binary to decial conversion = "<<cal<<endl;
                                    return 0;
                                }
                        
                    

Task 4.The date June 10, 1960 is special because when it is written as 10/6/60, the month times the day equals the year. Design a program that asks the user to enter a month (in numeric form), a day, and a two digit year. The program should then determine whether the month times the day equals the year. If so, it should display a message saying the date is magic. Otherwise, it should display a message saying the date is not magic.


                        
                            #include <iostream>
                                using namespace std;
                                int main()
                                {
                                    int days;
                                    int month;
                                    int year;
                                    int times;
                                    cout << "_____________________________________________________" << endl;
                                    cout << "-------------------Magic_Year_Validation-------------" << endl;
                                    cout << "_____________________________________________________" << endl;
                                    cout << "Enter the days:" << endl;
                                    cin >> days;
                                    cout << "Enter the month in numeric form like as june input as \"6\": etc:" << endl;
                                    cin >> month;
                                    cout << "Enter the last two digits of the year like as 1960 input as \"60\" etc:" << endl;
                                    cin >> year;
                                    // calculatios
                                    times = month * days;
                                    // Decisions
                                    if (times == year)
                                    {
                                        cout << "WOW!.Its amazing the year is a magic year:" << endl;
                                    }
                                    else
                                    {
                                        cout << "Ops! The enter year is not a magic year:" << endl;
                                    }
                                    return 0;
                                }
                        
                    

Task 5. Create a change-counting game that gets the user to enter the number of coins required to make exactly one dollar. The program should prompt the user to enter the number of pennies (1/100 dollars), nickels (1/20 dollars), dimes (1/10 dollars), and quarters (1/4 dollars). If the total value of the coins entered is equal to one dollar, the program should congratulate the user for winning the game. Otherwise, the program should display a message indicating whether the amount entered was more than or less than one dollar.


                        
                            #include <iostream>
                                using namespace std;
                                int main()
                                {
                                
                                    float pennies;
                                    float nickles;
                                    float dimes;
                                    float quarters;
                                    float total;
                                    cout << "_____________________________________________________" << endl;
                                    cout << "-------------------Count Changing game---------------" << endl;
                                    cout << "_____________________________________________________" << endl;
                                    cout << "Enter the coins required exactly to make the one doller:" << endl;
                                    cout << "Enter the pennies :" << endl;
                                    cin >> pennies;
                                    cout << "Enter the nickles :" << endl;
                                    cin >> nickles;
                                    cout << "Enter the dimes:" << endl;
                                    cin >> dimes;
                                    cout << "Enter the quarters :" << endl;
                                    cin >> quarters;
                                    // Calculations
                                    pennies = (pennies * 0.01);
                                    nickles = (nickles * 0.05);
                                    dimes = (dimes * 0.1);
                                    quarters = (quarters * 0.25);
                                    total = pennies + nickles + dimes + quarters;
                                    // Decisions
                                    if (total == 1)
                                    {
                                        cout << "Congratulations! you won the game : It is equal to the one dollar:" << endl;
                                    }
                                    else if (total > 1)
                                    {
                                        cout << "The coins entered are greater than 1 dollar:" << endl;
                                    }
                                    else
                                    {
                                        cout << "The coins entered are less than 1 dollar:" << endl;
                                    }
                                    return 0;
                                }
                        
                    

Task 6. Write a program that asks for the names of three runners and the time it took each of them to finish a race. The program should display who came in first, second, and third place. Input Validation: Only accept positive numbers for the times


                        
                            #include <iostream>
                                #include <string>
                                using namespace std;
                                int main()
                                {
                                
                                    string string1, string2, string3;
                                    int time1, time2, time3;
                                    cout << "_____________________________________________________" << endl;
                                    cout << "-------------------Running race----------------------" << endl;
                                    cout << "_____________________________________________________" << endl;
                                    cout << "Enter the name of the Player 1:" << endl;
                                    cin >> string1;
                                    cout << "Enter the time that took by player 1 to complete the race:" << endl;
                                    cin >> time1;
                                    cout << "Enter the name of the Player 2:" << endl;
                                    cin >> string2;
                                    cout << "Enter the time that took by player 2 to complete the race:" << endl;
                                    cin >> time2;
                                    cout << "Enter the name of the Player 3:" << endl;
                                    cin >> string3;
                                    cout << "Enter the time that took by player 3 to complete the race:" << endl;
                                    cin >> time3;
                                    // decisions
                                    if (time1 > 0)
                                    {
                                        if (time2 > 0)
                                        {
                                            if (time3 > 0)
                                            {
                                                // Condition--1
                                                if (time1 > time2)
                                                {
                                                    if (time1 > time3)
                                                    {
                                                        cout << string1 << " comes first with in a time of " << time1 << endl;
                                                        if (time2 > time3)
                                                        {
                                                            cout << string2 << " comes second with in a time of " << time2 << endl;
                                                            cout << string3 << " comes third  with in a time of " << time3 << endl;
                                                        }
                                                        if (time3 > time2)
                                                        {
                                                            cout << string3 << " comes second with in a time of " << time3 << endl;
                                                            cout << string2 << " comes third  with in a time of " << time2 << endl;
                                                        }
                                                    }
                                                }
                                                // Condition--2
                                                if (time2 > time1)
                                                {
                                                    if (time2 > time3)
                                                    {
                                                        cout << string2 << " comes first with in a time of " << time2 << endl;
                                                        if (time1 > time3)
                                                        {
                                                            cout << string1 << " comes second with in a time of " << time1 << endl;
                                                            cout << string3 << " comes third  with in a time of " << time3 << endl;
                                                        }
                                                        if (time3 > time1)
                                                        {
                                                            cout << string3 << " comes second with in a time of " << time3 << endl;
                                                            cout << string1 << " comes third  with in a time of " << time1 << endl;
                                                        }
                                                    }
                                                }
                                                // Condition--3
                                                if (time3 > time1)
                                                {
                                                    if (time3 > time2)
                                                    {
                                                        cout << string3 << " comes first with in a time of " << time3 << endl;
                                                        if (time1 > time2)
                                                        {
                                                            cout << string1 << " comes second with in a time of " << time1 << endl;
                                                            cout << string2 << " comes third  with in a time of " << time2 << endl;
                                                        }
                                                        if (time2 > time1)
                                                        {
                                                            cout << string2 << " comes second with in a time of " << time2 << endl;
                                                            cout << string1 << " comes third  with in a time of " << time1 << endl;
                                                        }
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                cout << "invalid input: The Time of " << string3 << " is in negative" << endl;
                                                cout << "Please enter the correct input!(Time is always in positive):" << endl;
                                            }
                                        }
                                        else
                                        {
                                            cout << "invalid input: The Time of " << string2 << " is in negative" << endl;
                                            cout << "Please enter the correct input!(Time is always in positive):" << endl;
                                        }
                                    }
                                    else
                                    {
                                        cout << "invalid input: The Time of " << string1 << " is in negative" << endl;
                                        cout << "Please enter the correct input!(Time is always in positive):" << endl;
                                    }
                                    return 0;
                                }
                        
                    

Task 7. A long-distance carrier charges the following rates for telephone calls: Write a program that asks for the starting time and the number of minutes of the call, and displays the charges. The program should ask for the time to be entered as a floating- point number in the form HH.MM. For example, 07:00 hours will be entered as 07.00, and 16:28 hours will be entered as 16.28. Input Validation: The program should not accept times that are greater than 23:59. Also, no number whose last two digits are greater than 59 should be accepted. Hint: Assuming num is a floating-point variable, the following expression will give you its fractional part:-


                        
                            #include <iostream>
                                #include <iomanip>
                                using namespace std;
                                int main()
                                {
                                    float time_start;
                                    float minutes;
                                    cout << "_____________________________________________________" << endl;
                                    cout << "-------------Long Distance Charge Carriers-----------" << endl;
                                    cout << "_____________________________________________________" << endl;
                                    cout << "Enter the started time of the call in the form HH.MM. as 07:45 :" << endl;
                                    cin >> time_start;
                                    // floating pointt get calculation
                                    int x;
                                    float y;
                                    x = time_start;
                                    y = time_start - x;
                                    cout << setprecision(2) << fixed;
                                    // Checkouts
                                    if (time_start > 23.59)
                                    {
                                        cout << "Invalid:input." << endl;
                                    }
                                    else if (y > 0.59)
                                    {
                                        cout << "Invalid:input." << endl;
                                    }
                                    else
                                    {
                                        //Input minutes long call from the user
                                        cout << "Enter the number of minutes the call long out:" << endl;
                                        cin >> minutes;
                                        //Check minutes validation
                                        cout << setprecision(2) << fixed;
                                        if (minutes - static_cast<int>(minutes) > 0.59)
                                        {
                                            cout << "Invalid:Input." << endl;
                                        }
                                        else
                                        {
                                            //Packages range decisions
                                            if (time_start >= 00.00)
                                            {
                                                if (time_start < 7.00)
                                                {
                                                    cout << "Total call charges = $" << minutes * 0.05 << endl;
                                                }
                                            }
                                
                                            if (time_start >= 07.00)
                                            {
                                                if (time_start <= 19.00)
                                                {
                                                    cout << "Total call charges = $" << minutes * 0.45 << endl;
                                                }
                                            }
                                
                                            if (time_start >= 19.01)
                                            {
                                                if (time_start <= 23.59)
                                                {
                                                    cout << "Total call charges = $" << minutes * 0.20 << endl;
                                                }
                                            }
                                        }
                                    }
                                
                                    return 0;
                                }
                          
                        
                    

Task 8.A mobile phone service provider has three different subscription packages for its customers:
Package A: For $39.99 per month 450 minutes are provided. Additional minutes are $0.45 per minute. Package B: For $59.99 per month 900 minutes are provided. Additional minutes are
$0.40 per minute. Package C: For $69.99 per month unlimited minutes provided. Write a program that calculates a customer’s monthly bill. It should ask which package the customer has purchased and how many minutes were used. It should then display the total amount due.
Input Validation: Be sure the user only selects package A, B, or C


                        
                            #include <iostream>
                                using namespace std;
                                int main()
                                {
                                
                                    char ch;
                                    int minutes;
                                    float extra_minutes;
                                    float extra_cost;
                                    float due_amount;
                                    cout << "_____________________________________________________" << endl;
                                    cout << "---------------Mobile Service Provider---------------" << endl;
                                    cout << "_____________________________________________________" << endl;
                                    cout << "Here are some packages for you:" << endl;
                                    cout << "\tPackage A: For $39.99 per month 450 minutes are provided." << endl
                                         << "\tAdditional minutes are $0.45 per minute." << endl;
                                    cout << endl;
                                    cout << "\tPackage B: For $59.99 per month 900 minutes are provided." << endl
                                         << "\tAdditional minutes are $0.40 per minute." << endl;
                                    cout << endl;
                                    cout << "\tPackage C: For $69.99 per month unlimited minutes provided." << endl;
                                    cout << endl;
                                    cout << "Now choose any one of the package that you want to apply:" << endl;
                                    cin >> ch;
                                    if (ch == 'A' || ch == 'a')
                                    {
                                        cout << "Enter the minutes you used:" << endl;
                                        cin >> minutes;
                                        if (minutes > 450)
                                        {
                                            extra_minutes = minutes - 450;
                                            extra_cost = extra_minutes * 0.45;
                                            due_amount = 39.99 + extra_cost;
                                            cout << "The due amount for the " << minutes << " minutes = $" << due_amount << endl;
                                        }
                                        else
                                        {
                                            cout << "The due amount for the " << minutes << " minutes = $39.99" << endl;
                                        }
                                    }
                                    else if (ch == 'B' || ch == 'b')
                                    {
                                        cout << "Enter the minutes you used:" << endl;
                                        cin >> minutes;
                                        if (minutes > 900)
                                        {
                                            extra_minutes = minutes - 900;
                                            extra_cost = extra_minutes * 0.40;
                                            due_amount = 59.99 + extra_cost;
                                            cout << "The due amount for the " << minutes << " minutes = $" << due_amount << endl;
                                        }
                                        else
                                        {
                                            cout << "The due amount for the " << minutes << " minutes = $59.99" << endl;
                                        }
                                    }
                                    else if (ch == 'C' || ch == 'c')
                                    {
                                        cout << "You have provided the unlimited minutes :" << endl;
                                        cout << "The due amount for the unlimited minutes = $69.99" << endl;
                                    }
                                    else
                                    {
                                        cout << "Invalid:input." << endl;
                                    }
                                    
                                    
                                    return 0;
                                    
                                }
                        
                    

Task 9.A county collects property taxes on the assessment value of property, which is 60 percent of the property's actual value. If an acre of land is valued at $10,000, its assessment value is $6,000. The property tax is then 75¢ for each $100 of the assessment value. The tax for the acre assessed at $6,000 will be $45. Write a program that asks for the actual value of a piece of property, then displays the assessment value and property tax.


                        
                            #include<iostream>
                                using namespace std;
                                int main()
                                {
                                    int actual_value;
                                    float assesment;
                                    float tax;
                                    cout << "_____________________________________________________" << endl;
                                    cout << "---------------------Property Tax--------------------" << endl;
                                    cout << "_____________________________________________________" << endl;
                                    cout<<"Entered the actual value of a piece of a property:"<<endl;
                                    cout<<"$";
                                    cin>>actual_value;
                                    //Calculations
                                    assesment=actual_value*0.6;
                                    tax=(assesment/100)*0.75;
                                    //Display
                                    cout<<"The assesment of the property = $"<<assesment<<endl;
                                    cout<<"The tax on the property = $"<<tax<<endl;
                                
                                
                                    return 0;
                                }
                        
                    

Task 10.While exercising, you can use a heart-rate monitor to see that your heart rate stays within a safe range suggested by your trainers and doctors. According to the American Heart Association (AHA), the formula for calculating your maximum heart rate in beats per minute is 220 minus your age in years. Your target heart rate is a range that’s 50–85% of your maximum heart rate. [Note: These formulas are estimates provided by the AHA. Maximum and target heart rates may vary based on the health, fitness and gender of the individual. Always consult a physician or qualified health-care professional before beginning or modifying an exercise program.] Create a program that reads the user’s birthday and the current day (each consisting of the month, day and year). Your program should calculate and display the person’s age (in years), the person’s maximum heart rate and the person’s target-heart-rate range


                        
                            #include<iostream>
                                #include<iomanip>
                                using namespace std;
                                int main()
                                {
                                    
                                    int year,month,date;
                                    int current_year,current_month,current_date;
                                    int maximum_heartRate;
                                    float target_heartRange;
                                    int age;
                                    cout << "_____________________________________________________" << endl;
                                    cout << "-------------(Target-Heart-Rate Calculator)----------" << endl;
                                    cout << "_____________________________________________________" << endl;
                                    cout<<"Enter the year of your birth:"<<endl;
                                    cin>>year;
                                    cout<<"Enter the month of your birth:"<<endl;
                                    cin>>month;    
                                    cout<<"Enter the date of your birth:"<<endl;
                                    cin>>date;
                                    cout<<endl;
                                    cout<<endl;
                                    cout<<endl;
                                    cout<<"Enter the current year:"<<endl;
                                    cin>>current_year;
                                    cout<<"Enter the current month:"<<endl;
                                    cin>>current_month;
                                    cout<<"Enter the current date:"<<endl;
                                    cin>>current_date;
                                    //Age calculate
                                    if(current_month>=month && current_date>=date)
                                    {
                                        age=current_year-year;
                                        cout<<"You are "<<age<<" years old:"<<endl;
                                    }
                                    else
                                    {
                                        age=(current_year-year)-1;
                                        cout<<"You are "<<age<<" years old:"<<endl;
                                    }
                                    //Maximum-Heart-rate
                                    maximum_heartRate=220-age;
                                    cout<<"The maximum Heart Rate of your Heart = "<<maximum_heartRate<<" beats/minute"<<endl;
                                    //Target-Haert-Range
                                    //average_heartRate=(50+85)/2==67.5%
                                    //67.5/100==0.675%
                                    cout<<setprecision(2)<<fixed;
                                    target_heartRange=(float)(maximum_heartRate*0.675);
                                    cout<<"The Target Heart Range = "<<target_heartRange<<endl;	
                                
                                    return 0;
                                }