{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

C++ - Exercise 4#include"stdafx.h#include using...

Info icon This preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Exercise 4 #include "stdafx.h" #include <iostream> using namespace std; int main () { int a, b, c, sum; cout << "Enter in a number. " ; cin>> a; cout << "Please enter another number. " ; cin>> b; cout << "Enter one more number. " ; cin>> c; sum = a + b + c; cout<< "The sum of the number is..." << sum; return 0; } Exercise 5 // cin & cout #include "stdafx.h" #include <iostream> using namespace std; int main () { int a, b, c, x, y; a=4; b=3; c=2; cin>>x; y=a*x*x+b*x+c; cout<<y; return 0; } Exercise 6 #include "stdafx.h" #include <iostream> using namespace std; int main () { int a, x, y; a=5; cin>>x; y=a*x*x*x+7; cout<<y; return 0; }
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Exercise 7 #include "stdafx.h" #include <iostream> using namespace std; int main () { int a,b,c; cin>>a; b=a*a; c=a*a*a; cout<<b<< "\n" ; cout<<c; return 0; } Exercise 8 #include "stdafx.h" #include <iostream> using namespace std; int main () { int a, b, c; cout<< "\nEnter a number..." ; cin>> a; cout << "\nEnter another number..." ; cin>>b; if (a>b) cout<< "\n" <<a<< "is larger\n" ; else cout<< "\n" <<b<< "is larger\n" ; return 0; } Exercise 9 #include "stdafx.h" #include <iostream> using namespace std; int main () { int a,b,c,d,e,s; cin>>a; cin>>b; cin>>c; cin>>d; cin>>e; if (a>b) s=a; else s=b; if (s>c) s=s;
Image of page 2
else s=c; if (s>d) s=s; else s=d; if (s>e) s=s; else s=e; cout<<s<< "is the largest\n" ; return 0; } Exercise 10 #include "stdafx.h" #include <iostream> using namespace std; int main () { int b, i, j, l; char ba; float ia; double ja; int la; l= sizeof (la); cout<< "The size of an integer is..." <<l<< '\n' ; b= sizeof (ba); cout<< "The size of a character is..." <<b<< '\n' ; i= sizeof (ia); cout<< "The size of a floating point is..." <<i<< '\n' ; j= sizeof (ja); cout<< "The size of a double precision floating point is..." <<j<< '\n' ; cout<< "Void is not a data type.\n" ; return 0; } Exercise 11 #include "stdafx.h" #include <iostream> using namespace std; int main () { int r, d, c, a; cout<< "What is the radius?\n" ; cin>>r; d=2*r; cout<< "The diameter is" <<d<< "\n" ; const float pi=3.14159; c=pi*d; cout<< "The circumference is" <<c<< "\n" ; a=pi*r*r; cout<< "The area is" <<a<< "\n" ; return 0;
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
} Exercise 12 #include "stdafx.h" #include <iostream> using namespace std; int main () { int a, b; cout<< "Enter a number.." ; cin>>a; b=a%2; if (b==0) cout<< "The number is even.\n" ; else cout<< "The number is odd.\n" ; return 0; } Exercise 13 #include "stdafx.h" #include <iostream> using namespace std; int main () { int me, luv, him; cout<< "The first number is.." ; cin>>me; cout<< "The second number is.." ; cin>>luv; him=me%luv; if (him!=0) cout << "The first number is not multiple of the second number.\n" ; else cout << "The first number is a multiple of the second number.\n" ; return 0; } Exercise 14 #include "stdafx.h" #include <iostream> using namespace std; int main () { int n; char x; n= sizeof (x); cout<<n<< '\n' ; cin>>x; cout<< '\n' <<x<< '\n' ; cout<< static_cast < int >(x)<< '\n' ;
Image of page 4
//convert integer to Boolean number obtains the ASCII code return 0; } Exercise 15 #include "stdafx.h" #include <iostream> using namespace std; int main () { int a; cout<< "Enter the student's grade. " ; cin>>a; { if (a>=60) cout<< "The student passed." <<endl; else cout<< "The student didn't pass." <<endl; } { if (a>=90) cout<< "The student's grade is an A.\n" ; else if (a<90&&a>=80) cout<< "The student's grade is a B.\n" ; else if (a<80&&a>=70) cout<< "The student's grade is a C.\n" ; else if (a<70&&a>=60) cout<< "The student's grade is a D.\n"
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern