Thread: C++ Help
View Single Post
Old 11-08-2008   #9
Sheriff Ice
info@sync.com.lb
 
Sheriff Ice's Avatar
 
Last Online: 11-29-2020
Join Date: Apr 2006
Posts: 3,827
Thanks: 1,348
Thanked 2,391 Times in 1,306 Posts
Groans: 0
Groaned at 16 Times in 15 Posts
Default Re: C++ Help

Code:
1.23
  
  #include<iostream>
  using namespace std;
  int main()
  {
            int x,y;
            cout<<"enter your first integer:\n";
            cin>>x;
            cout<<endl<<"enter your second integer:\n";
            cin>>y;
            cout<<endl<<"the sum is:  "<<x+y<<endl<<"the product is:  "<<x*y<<endl<<"the difference is:  "<<x-y<<endl<<"the quotion is:  "<<x/y<<endl;
            return 0;
  }
  
  1.24
  
  #include<iostream>
  using namespace std;
  int main()
  {
            int x;
            x=0;
            if(x<=4)
            cout<<x;
            return 0;
  }
  
  1.25
  
  #include<iostream>
  using namespace std;
  int main()
  {
            int x,y;
            cout<<"enter your first integer; \n";
            cin>>x;
            cout<<endl<<"enter your second integer; \n";
            cin>>y;
            cout<<endl;
            if(x>y)
                     cout<<x<<" is larger"<<endl;
            else if(y>x)
                     cout<<y<<" is larger"<<endl;
            else if(x==y)
                     cout<<"these number are equal  "<<x<<" = "<<y<<endl;
            return 0;
  }
   
  
  
  
  1.26
   
  #include<iostream>
  using namespace std;
  int main()
  {
            int x,y,z,sum,ave,pro;
            cout<<"Input three different integers: ";
            cin>>x>>y>>z;
            sum=x+y+z;
                     cout<<"sum is "<<sum<<endl;
                     ave=(x+y+z)/3;
                               cout<<"average is "<<ave<<endl;
                     pro=x*y*z;
                     cout<<"product is "<<pro<<endl;
            return 0;
  }
   
  1.30
  
  #include<iostream>
  using namespace std;
  int main()
  {
            int a,b,c,d,e;
            cout<<"enter the 5 values:\n";
                     cin>>a>>b>>c>>d>>e;
            if(a<b,a<c,a<d,a<e)
                     cout<<"the smallest "<<a<<endl;
            else if(b<a,b<c,b<d,b<e)
                     cout<<"the samallest "<<b<<endl;
            else if(c<a,c<b,c<d,c<e)
                     cout<<"the smallest "<<c<<endl;
            else if(d<a,d<b,d<c,d<e)
                     cout<<"the smallest "<<d<<endl;
            else  
                     cout<<"the smallest "<<e<<endl;
  }
  {
            if(a>b,a>c,a>d,a>e)
                     cout<<"the largest "<<a<<endl;
            else if(b>a,b>c,b>d,b>e)
                     cout<<"the largest "<<b<<endl;
            else if(d>a,d>b,d>c,d>e)
                     cout<<"the largest "<<d<<endl;
            else if(c>a,c>b,c>d,c>e)
                     cout<<"the largest "<<c<<endl;
            else
                     cout<<"the largest "<<e<<endl;
            return 0;
  }
   
  1.31
   
  #include<iostream>
  using namespace std;
  int main()
  {
            int x,y;
            cout<<"enter your integer: \n";
            cin>>x;
            if(x%2)
                     cout<<x<<" is even\n";
            else
                     cout<<x<<" is odd\n";
            cout<<"enter your integer \n";
            cin>>y;
            if(y%2)
                     cout<<y<<" is even\n";
            else
                      cout<<x<<" is odd\n";
            return 0;
  }
   
  1.32:
  x 1.32:
   
  #include <iostream>
  using namespace std;
  int main()
  {
            int x,y;
            cout<<"Enter two integers\n";
      cin>>x>>y;
            if (x%y==0)
                     cout<<x<<"is multiple of"<<y;
            return 0;
  }

<!--  /* Font Definitions */  @font-face 	{font-family:&quot;Cambria Math&quot;; 	panose-1:2 4 5 3 5 4 6 3 2 4; 	mso-font-charset:1; 	mso-generic-font-family:roman; 	mso-font-format:other; 	mso-font-pitch:variable; 	mso-font-signature:0 0 0 0 0 0;}  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-unhide:no; 	mso-style-qformat:yes; 	mso-style-parent:&quot;&quot;; 	margin:0in; 	margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:12.0pt; 	font-family:&quot;Times New Roman&quot;,&quot;serif&quot;; 	mso-fareast-font-family:&quot;Times New Roman&quot;; 	mso-bidi-language:AR-LB;} .MsoChpDefault 	{mso-style-type:export-only; 	mso-default-props:yes; 	font-size:10.0pt; 	mso-ansi-font-size:10.0pt; 	mso-bidi-font-size:10.0pt;} @page Section1 	{size:8.5in 11.0in; 	margin:1.0in 1.0in 1.0in 1.0in; 	mso-header-margin:.5in; 	mso-footer-margin:.5in; 	mso-paper-source:0;} div.Section1 	{page:Section1;} -->     
EX:2.16:
#include<iostream> //chapter 2 ex2.16 using namespace std; int main() { double galon,mil,total,m,ave; m=0; total=0; cout<<"enter the gallons used, -1 to end: \n"; cin>>galon; while(galon!=-1) { total=total+galon; cout<<"enter miles driven: \n"; cin>>mil; m=m+mil; cout<<"the miles/gallons for this tank was "<<mil/galon; //average for one entry cout<<endl<<"enter the gallons used, -1 to end: \n"; cin>>galon; } ave=(m/total); cout<<"the overall average is: "<<ave<<endl; //the overall average. return 0; } Ex:2.17: #include<iostream> #include<iomanip> using namespace std; int main() { int an; double bb,tc,cr,cl,b; cout<<"Enter the account number: (-1 to end)"<<endl; cin>>an; while(an!=-1) { cout<<"Enter the beginning balance: "<<endl; cin>>bb; cout<<endl<<"Enter total charges:"<<endl; cin>>tc; cout<<endl<<"Enter total credits: "<<endl; cin>>cr; cout<<endl<<"Enter credit limit: "<<endl; cin>>cl; cout<<endl; b=bb+tc-cr; if(b>=cl) { cout<<"Account"<<setw(8)<<an<<endl; cout<<"credit limit"<<setw(4)<<cl<<endl; cout<<"Balance"<<setw(8)<<b<<endl; cout<<"Credit limit exceeded"<<endl; } cout<<endl<<endl; cout<<"enter the account number: (-1 to end)"<<endl; cin>>an; } return 0; } Ex:2.18: #include<iostream>//exercise2.18 page 160 using namespace std; int main() { int ws; double sales,total,commission; ws=200; cout<<"enter sales in dollars (-1 to end):"<<endl; cin>>sales; while(sales!=-1) { commission=(9*sales)/100; total=ws+commission; cout<<"salary is: $"<<total<<endl<<endl; cout<<"enter sales in dollars (-1 to end):"<<endl; cin>>sales; } return 0; } Ex:2.19: #include<iostream> using namespace std; int main() { int hours,ratelow,extra; double ratehigh,bonus;; cout<<"enter hours worked (-1 to end)\n"; cin>>hours; while(hours!=-1) { cout<<"enter hourly rate of the worker($00.00): "<<endl; cin>>ratelow; ratehigh=ratelow*1.5; if(hours>40) { extra=hours-40; bonus=extra*ratehigh; cout<<"the salary is:$"<<bonus+40*ratelow<<endl; } else cout<<"the salary is:$"<<hours*ratelow<<endl<<endl; cout<<"enter hours worked (-1 to end)"<<endl; cin>>hours; } return 0; } Ex:2.20: #include<iostream> using namespace std; int main() { int counter=0,number=0,large=0; cout<<"enter number of sold objects\n"; cin>>number; while(counter<=10) { counter=counter+1; if(number>=large)large=number; cout<<"enter the number of sold objects\n"; cin>>number; } cout<<"the most sold is "<<large; return 0; } Ex:2.21: #include<iostream> using namespace std; int main() { int x; x=1; cout<<"N\t10*N\t100*N\t1000*N\n\n"; while(x<=5) { cout<<x<<"\t"<<x*10<<"\t"<<x*100<<"\t"<<x*1000<<endl;x++; } return 0; } problem 1: #include <iostream> using namespace std; void prime(int,int); int main() { int a,b; cout<<"enter the domain between 2 numbers u need to find the prime numbers:"<<endl; cin>>a>>b; prime(a,b); return 0; } void prime(int a,int b) { int i; int num=0; for (int j=a;j<=b;j++) { num=num+1; for (i=2; i<num; i++) { if((num%i)==0) { break; } } if (i >= num) { cout<<num<<endl; } } } problem 2 #include <iostream> #include <cmath> using namespace std; int main() { const int maxNumb = 10000; int sum, largestFactor, divisor; double started, ended; for (int lcv = 2; lcv < maxNumb; ++lcv) { sum = 1; largestFactor = (int)sqrt((double)lcv); for (divisor = 2; divisor <= largestFactor; ++divisor) { if (lcv % divisor == 0) { sum += divisor; if (divisor * divisor != lcv) sum += (lcv / divisor); } if (sum > lcv) break; } if (sum == lcv) cout << lcv << endl; } return 0; } problem 4 #include<iostream> #include<cstdlib> using namespace std; int main() { int x,y,z,a; while(a!=-1) { x=(1+rand() %9); y=(1+rand() %9); z=x*y; cout<<"how much is "<<x<<" times "<<y<<" ?"<<endl; cin>>a; while (a!=z) { cout<<endl<<"No, plz try again"<<endl; cin>>a; } cout<<"very good"<<endl; cout<<"enter -1 to exit or any number to continue"; cin>>a; } return 0; } problem 5 #include<iostream> #include<cstdlib> using namespace std; int main() { int x,y; char c; cout<<"want to play (y or n)"<<endl; cin>>c; while(c==y) { x=(1+rand()%1000); cout<<"i have a number between 1 and 1000."<<endl; cout<<"can you guess my number?"<<endl; cout<<"please type ur first guess"<<endl; cin>>y; while(y!=x) { if(y<=(x-10)) cout<<"Too low. Try again."<<endl; else if(y<x) cout<<"almost there."<<endl; else if(y>=(x+10)) cout<<"too high. Try again."<<endl; else if(y>10) cout<<"almost there."<<endl; cin>>y; } cout<<"excellent! you guessed the number!"<<endl; cout<<"would you like to play again (y or n)?"; cin>>c; } return 0; } problem 6 #include<iostream> #include<iomanip> #include<cstdlib> using namespace std; int main() { int tim1=0,tim2=0,tim3=0,tim4=0,tim5=0,tim6=0,face; for(int roll=1;roll<=6000;roll++) { face=1+rand()%6; switch (face) { case 1: ++tim1; break; case 2: ++tim2; break; case 3: ++tim3; break; case 4: ++tim4; break; case 5: ++tim5; break; case 6: ++tim6; break; default : cout<<"program should never get here!"; } } cout<<"Face"<<setw(15)<<"Times" <<"\n 1"<<setw(15)<<tim1 <<"\n 2"<<setw(15)<<tim2 <<"\n 3"<<setw(15)<<tim3 <<"\n 4"<<setw(15)<<tim4 <<"\n 5"<<setw(15)<<tim5 <<"\n 6"<<setw(15)<<tim6<<endl; return 0; } problem 11 #include<iostream> using namespace std; void draw_ESquare(int,char); int main () { int l;char c; cout<<"enter the character the lenght of your square: \n"; cin>>c>>l; cout<<endl; draw_ESquare(l,c); return 0; } void draw_ESquare(int l, char c) { for(int i=1;i<=l;i++) { for(int j=1;j<=l;j++) if(i==1||j==l) cout<<c; else cout<<" "; cout<<endl; } }
sorry i dont have the questions but if u read each example u will know what it do

these are the exercises that i found

i still have two e-books

c++ ill post them later by tonight
__________________
http://www.gamync.com Lebanese Produced Mobiles Games by http://www.sync.com.lb
Sheriff Ice is offline   Reply With Quote