Question

Hi guys just starting out programming and my professor doesn't really explain it that much can you help me with this lab of mine in c++ and yes I'll give you points for it thank you!

Lab #1

/Part A:
//Input number 1 (store in var1)
//Input number 2 (store in var2)
//Swap them, so number 1 is in var2 and number 2 is in var1
//Output the numbers to stdout (cout)
//Multiply var1 by 2
//Divide var2 by 2
//Output the results again (cout)

//Part B:
//Take as input a radius of a circle from the user (cin)
//Output the circumference of the circle and area of the circle (cout)

//Part C:
//Goal: Refresh int, floats, chars, strings.
//Take as input a quantity of fruits (number of apples) (cin)
//Take as input price per apple
//Output the total price for all apples bought

//Part D:
//Take as input the name of a student (cin)
//Take as input the grade she got in a course (cin)
//Output the name and the grade (cout)

//Part E:
//Goal: test comparison operators and multiple cases of variable values
//Take as input a grade (A B C D or F)
//Output a description of the grade (what it means "Excellent" or ... "Failed")
//Take as input a year of graduation (2000)
//Output in how many years she will graduate (or if she has graduated already)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Part A:

Code:

#include <iostream>

using namespace std;

int main()
{
   int var1,var2;
   cout<<"Input the numbers : Number 1 : ";
   cin>>var1;//input number1
   cout<<"Number 2 : ";
   cin>>var2;//input number2
   int temp;//to store 1 number temprorily
   temp=var1;
   var1=var2;
   var2=temp;//it now has value of var1
   cout<<"Number 1 : "<<var1<<" Number 2 : "<<var2;
   var1=var1*2;
   var2=var2*2;
   cout<<"\nNumber 1 : "<<var1<<" Number 2 : "<<var2;// \n is for new line


    return 0;
}


Output:

Input the numbers : Number 1 : 1                                                                                                                              

Number 2 : 2                                                                                                                                                  

Number 1 : 2 Number 2 : 1                                                                                                                                     

Number 1 : 4 Number 2 : 2     

PART B

Code:

#include <iostream>

using namespace std;

int main()
{
   int r;
cout<<"Input radius of circle : ";
cin>>r;//input radius
cout<<"\nCircumference is : "<<2*3.14*r;
cout<<"\nArea is : "<<3.14*r*r;

    return 0;
}


Output:

Input radius of circle : 5                                                                                                                                    

                                                                                                                                                              

Circumference is : 31.4                                                                                                                                       

Area is : 78.5   

PART C

Code:

#include <iostream>

using namespace std;

int main()
{
   int quantity;
   float price;
   cout<<"Enter quantity of apples : ";
   cin>>quantity;//input quantity
   cout<<"Enter price per apple : $";
   cin>>price;//input price
   cout<<"Total price of apples bought : $"<<quantity*price;


    return 0;
}


Output:

Enter quantity of apples : 7                                                                                                                                  

Enter price per apple : $33.2                                                                                                                                 

Total price of apples bought  : $232.4

PART D

Code:

#include <iostream>

using namespace std;

int main()
{
   string name;//name must be string type
   char grade;
   cout<<"Enter name of student : ";
   cin>>name;
   cout<<"Enter grade of student : ";
   cin>>grade;
   cout<<"Name : "<<name<<"\nGrade : "<<grade;//displaying name and grade



    return 0;
}


Output:

Enter name of student : John                                                                                                                                  

Enter grade of student : A                                                                                                                                    

Name : John                                                                                                                                                   

Grade : A  

PART E

Code:

#include <iostream>

using namespace std;

int main()
{

   char grade;

   cout<<"Enter grade of student : ";
   cin>>grade;
   if(grade=='A')
   cout<<"\nExcellent";
   else if(grade=='B')
   cout<<"\nVery Good";
   else if(grade=='C')
   cout<<"\nGood";
   else if(grade=='D')
   cout<<"\nAverage";
   else
   cout<<"\nFailed";
   int year;
   cout<<"\nEnter a year of education :";
   cin>>year;
   if(year+4<2019)//assuming current year is 2019 and 4 years are for graduation
   cout<<"She is graduated already!";
   else
   cout<<"She will graduate in "<<4-(2019-year)<<"years";



    return 0;
}


Output:

Enter grade of student : A                                                                                                                                    

                                                                                                                                                              

Excellent                                                                                                                                                     

Enter a year of education :2018                                                                                                                               

She will graduate in 3years    

Add a comment
Know the answer?
Add Answer to:
Hi guys just starting out programming and my professor doesn't really explain it that much can...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++

    Need Help with this homework assignment:Week 4: Constructors and Destructors - iLab HelpLab 4 of 7: C++ Constructors (40 Points)L A B O V E R V I E WSummaryIn this lab, you will apply the knowledge you have gained this week by illustrating solutions to a programming problem using Visual Studio and C++. Use your textbookand lecture as a resource in completing the requirements of this lab.Deliverables1. Submit to Week 4's Dropbox, a single Notepad file containing the source...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT