arrow
arrow

PF-PUCIT(NEW-CAMPUS)

ASSIGNMENT 01:

Sample:Sum_Of_Two_Numbers


                            
                                #include<iostream>
                                    using namespace std;
                                    int main()
                                    {
                                        int num_1=50;
                                        int num_2=100;
                                        int sum;
                                        sum=num_1+num_2;
                                        cout<<"The sum of these two numbers = "<<sum<<endl;
                                        return 0;
                                    }
                                    
                            
                        

To see the assignment in pdf form


Practice these questions by yourself then see codecheets😂


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

DOWnload PDF HERE

Task 1. Write a program that displays size of int, float, double, char and bool data types, use sizeof() function.


                        
                            /* This Program is used to display the size of different dataTypes 
                            Key_point:
                                 We use the function sizeof(dataTypes) :
                          */
                          #include<iostream>
                          using namespace std;
                          int main()
                          {
                              
                              cout<<"The size of Int_data_Type  is "<<sizeof(int)<<" Bytes \n";
                              cout<<"The size of Float_data_Type  is "<<sizeof(float)<<" Bytes \n";
                              cout<<"The size of Double_data_Type  is "<<sizeof(double)<<" Bytes \n";
                              cout<<"The size of Char_data_Type is  "<<sizeof(char)<<" Bytes \n";
                              cout<<"The size of Bool_data_Type is  "<<sizeof(bool)<<" Bytes \n";
                          
                              return 0;
                          }
                          
                        
                    

Task 2. Write a program that compute area of a rectangle, whose height if 9m and width is 5m.Display its area.


                        
                            /*This is a Program to display the area of arectangle
                            Key_point:
                               area=height*Width;
                         */
                         #include<iostream>
                         using namespace std;
                         int main()
                         {
                             
                             int height=9;
                             int width=5;
                             int area=0;//Intiliaze to zero to overwrite the garbage value
                             cout<<"Calculate the area of a rectangle:"<<endl;
                             cout<<"height=9m"<<endl;
                             cout<<"width=5m"<<endl;
                             area=height*width;
                             cout<<"The area of a rectangle = "<<area<<"m^2"<<endl;
                             
                             return 0;
                         }
                        
                    

Task 3. Write a program that displays sum, subtractions, multiplication and division of two float numbers. Take any float numbers i.e. float f1 = 5.4, f2 = 7.8;


                        
                            /*This is a program that dispaly the sum,subtraction ,multiplication and division 
                            of the two "Float_numbers"*/
                           #include<iostream>
                           using namespace std;
                           int main()
                           {
                               
                               float num1=5.4;
                               float num2=7.2;
                               float sum=0;//Initilaize to zero to overwrite the garbage values
                               float sub=0;
                               float multiplay=0;
                               double division=0;//Take is double because its a chance to get the point values greater than float range
                               cout<<"we have two numbers:"<<endl;
                               cout<<"Number_1=5.4 \n";
                               cout<<"Number_2=7.2 \n";
                               cout<<endl;
                               cout<<"The arthematic_operations on these floating point numbers:"<<endl;
                               cout<<endl;
                               //Araathematic Operations on it
                               sum=num1+num2;
                               sub=num1-num2;
                               multiplay=num1*num2;
                               division=num1/num2;
                               cout<<"The Addition of these two floating numbers = "<<sum<<endl;
                               cout<<"The Subtraction of these two floating numbers = "<<sub<<endl;
                               cout<<"The Multiplication of these two floating numbers = "<<multiplay<<endl;
                               cout<<"The division of these two floating numbers = "<<division<<endl;
                           
                               return 0;
                           }
                        
                    

Task 4. Write reasons for errors in following codes:
int number = 10;
cout << number;
cout << number2;
int number2 = 50;
char ch = 'Programming Fundamental ';
cout << ch ;


                        
                            /*
                            Errors in the code*/
                          #include<iostream>
                          using namespace std;
                          int main()
                          {
                              cout<<"we have a code as:"<<endl<<endl<<"int number = 10"
                              <<endl<<"cout << number;"<<endl<<"cout << number2;"<<endl
                              <<"int number2 = 50;"<<endl<<"char ch = 'Programming Fundamental;"
                              <<endl<<"cout << ch ;";
                              cout<<endl;
                              cout<<"The errors in the code are as follows;"<<endl<<endl;
                              cout<<endl;
                              
                              cout<<"First ERROR:"<<endl;
                              cout<<"In the third line we cout the number2 first and decalre and initlize it later.Its scope is invalid because C++ compilers compile it line by line "<<endl
                              <<"The error is \" SCOPE_Invalid : a variable cannot be used in any part of the program before the definition\" "<<endl;
                              cout<<endl;
                              
                              cout<<"Second_ERROR:"<<endl;
                              cout<<"IN fifth_line we initiliaze the char datatype with a string but char dataType has store only one ASCII character and size of its is only one bit"<<endl
                              <<"The error is \"  Strings are consecutive sequences of characters that occupy consecutive bytes of memory \" "<<endl
                              <<"Characters normally occupy a single byte of memory:"<<endl; 
                              cout<<endl;
                              
                              return 0;
                          }
                        
                    

Task 5. Write a program that converts Fahrenheit temperature to Celsius temperature. Initialize a variable with Fahrenheit temperature value i.e float Fahrenheit = 35; And convert it into Celsius
temperature. Hint: Celsius = (Fahrenheit - 32) * 5/9
Sample Output:
Temperature in Fahrenheit : 212
Temperature in Celsius : 100


                        
                            /*This is program to display the Celsius to fanheit temparature
                            Key point:
                                  celsius=(farnheit-32)*5/9;
                           */
                           #include<iostream>
                           using namespace std;
                           int main()
                           {
                               
                               double farnheit=212;
                               double celsius=0;//Intiliaze to zero to overwrite the garbage value
                               celsius=(farnheit-32)*5/9;//Parantesis are used to discarge the priority order of division
                               cout<<"The temperature in Farnheit = "<<farnheit<<endl;
                               cout<<"The temperature in Celsius = "<<celsius<<endl;
                               return 0;
                               
                           }
                        
                    

Task 6. Write a program that swaps value of two integer. Display values before and after swapping. Hint: Take help from third variable.
Sample Output:
Before Swapping:
Value of no1 = 5
Value of no2 = 10
After Swapping:
Value of no1 = 10
Value of no2 = 5


                        
                            /*This is a program to Swap the values
                            key_Point:
                               {
                                 int a,b,temp;
                                 temp=a;
                                 a=b;
                                b=temp;
                            }    
                          */
                          #include<iostream>
                          using namespace std;
                          int main()
                          {
                              int num1=5;
                              int num2=10;
                              int temp=0;//used the third variable for help
                              cout<<"The Numbers before swaping are written as:"<<endl;
                              cout<<"The number_1 = "<<num1<<endl;
                              cout<<"The number_2 = "<<num2<<endl;
                              cout<<endl;
                              //Now Swap the Values
                              temp=num1;
                              num1=num2;
                              num2=temp;
                              cout<<"The Numbers After swaping are written as:"<<endl;
                              cout<<"The number_1 = "<<num1<<endl;
                              cout<<"The number_2 = "<<num2<<endl;
                              cout<<endl;
                              
                              return 0;
                          }
                        
                    

Task 7. Write a program that stores your name, rollno, age and degree in valid data type variables. And displays in following format:
Hi, my name is ------- having roll number ------- and enrolled in -------. My age is -----


                        
                            /*Program to display the Information
                            Key_point:
                                 we use the string library and strimg dataType to store the stings*/
                          #include<iostream>
                          #include<string>
                          using namespace std;
                          int main()
                          {
                              //use the string dataType because we cannot store the more than one 
                              //letter in char dataType so to store the complete string we use the string dataType in 
                              //string libraray
                              string name="Muhib Arshad";
                              string roll_no="BSEF21M540";
                              string enrolled="FCIT(New_Campus) BSSE";
                              int age=19;
                              cout<<"My name is "<<name<<" having roll number "<<roll_no<<" and enrolled in "<<enrolled<<". My age is "<<age<<endl;
                              return 0;
                              
                          }
                          
                        
                    

Task 8. Write a program that displays average of three numbers. Hardcode values of variables


                        
                            /*Program to display the Average of three variables*/
                            #include<iostream>
                            using namespace std;
                            int main()
                            {
                                
                                int num1=5;
                                float num2=8.9;
                                double num3=9.888;
                                double average=0;//Intiliaze to zero to overwrite the garbage value
                                average=(num1+num2+num3)/3;//Parantesis are used to discarge the priority order of division
                                cout<<"Number 1 = "<<num1<<endl;
                                cout<<"Number 2 = "<<num2<<endl;
                                cout<<"Number 3 = "<<num3<<endl;
                                cout<<"The average of these three numbers = "<<average<<endl;
                                return 0;
                                
                            }
                        
                    

Task 9. Write a program in which you store float value in int variable. Explain the output.


                        
                            /*Program to check float in int*/
                            #include<iostream>
                            using namespace std;
                            int main()
                            {
                                int num1=7.98;
                                cout<<"The number_1 is equal to = "<<num1<<endl;
                                cout<<endl;
                                
                                cout<<"Explanation:"<<endl;
                                cout<<"I store the varible in int as 7.98 in source code but in console answer is 7"<<endl
                                <<"Beacuse when we store the floating point variable in int dataType it ignores the values after the(.)"<<endl
                                <<"Integer dataType only stores the integer values without point values"<<endl
                                <<"To store the variable with the point_values we use the float dataType properly"<<endl;
                                
                                return 0;
                                
                            }
                        
                    

Task 10. Suppose an employee gets paid every month and earns 2000 each pay period. In a year the employee gets paid 12 times. Write a program that defines the following variables:
payAmount; this variable will hold the amount of pay the employee earns each pay period.
payPeriods; this variable will hold the number of pay periods in a year.
annualPay; this variable will hold the employee’s total annual pay, which will be calculated.
Display the value of annualPay variable.
Hint: Employee’s total annual pay can be calculated by multiplying employee’s pay amount by number of pay periods in a year


                        
                            /*Program to display the anual_pay of user income */
                            #include<iostream>
                            using namespace std;
                            int main()
                            {
                                
                                int pay_Amount=2000;
                                int pay_Periods=12;
                                int annual_Pay=0;//Intiliaze to zero to overwrite the garbage value
                                cout<<"The amount of pay the employee earns each pay period = "<<pay_Amount<<endl;
                                cout<<"The number of pay periods in a year = "<<pay_Periods<<endl;
                                annual_Pay=pay_Amount*pay_Periods;
                                cout<<"The employee\'s total annual pay, which will be calculated = "<<annual_Pay<<endl;
                                
                                return 0;
                            }
                        
                    

Whats make this website differents from others?

Amazing Feature That Increase your Productivity

If you don't find any problem,in this website and if you have a very difficult assignment question that is not present on internet ,then you dont bother yourself,we are here to solve every problem of your life you just click on the Problem asking button and write your problem we slove the code of your problem and sent you on your email addres that you put in the sin up form.