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)
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
Hi guys just starting out programming and my professor doesn't really explain it that much can...