- Write a program that takes a character from A to Z and convert it into lower-case character. (use type casting)
Thursday, November 27, 2014
4. Write a program that takes a character from A to Z and convert it into lower-case character. (use type casting)
display a * pattern bynb setwidth manipulator
- Write a program to display the following pattern using setw:
*
***
*****
*******
#include <iostream>
#include <iomanip> //introducing library for setw() manipulator
using namespace std;
int main()
{
cout<<setw(6)<<"*\n" //setting set width
<<setw(7)<<"***\n" //setting set width
<<setw(8)<<"*****\n" //setting set width
<<setw(9)<<"*******\n"; //setting set width
return 0;
}
Find the no of cookies!!!!!!!!!!
- A bag of cookies holds 40 cookies. The calorie information on the bag claims that there are 10 “servings” in the bag and that a serving equals 300 calories. Write a program that asks the user to input his/her name and how many cookies he or she actually ate and then reports how many total calories were consumed.
Wednesday, November 26, 2014
1. Write a program that asks for five test scores. The program should calculate the average test score and display it. The number displayed should be formatted in fixed-point notation, with one decimal point of precision. (use of while loop is optional)
1.
Write a program that asks for
five test scores. The program should calculate the average test score and
display it. The number displayed should be formatted in fixed-point notation,
with one decimal point of precision. (use of while loop is optional)
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int s1,s2,s3,s4,s5;
double avg,sum;
cout<<"Enter first test score = ";
cin>>s1;
cout<<"Enter 2nd test score = ";
cin>>s2;
cout<<"Enter 3rd test score = ";
cin>>s3;
cout<<"Enter 4rth test score = ";
cin>>s4;
cout<<"Enter fifth test score = ";
cin>>s5;
sum=s1+s2+s3+s4+s5;
avg=sum/5;
cout<<"The average= "<<setprecision(1)<<fixed<<avg<<endl;
return 0;
}
Use of setwidth operator in c++
Use of setwidth operator in c++
/*use of setw() output formator usually it is automatically right
sewidth which are formatted numbers are written on right side spaces are placed at
left this is right justified but adding only word left it will become
left justified we have to only add <<left before <<setw()<<value;
numbers are automatically riht justified but if we want to place right word just like
<<right before stw()<<value */
/*in order to make following program right justified just remove <<left from syntax */
#include <iostream>
using namespace std;
#include <iomanip>
int main()
{
int n1=3,n2=4,n3=435,n4=2453,n5=4535,
n6=43232,n7=231534,n8=25434,n9=2423;
cout<<left<<setw(7)<<n1<<left<<setw(7)<<n2<<left<<setw(7)<<n3<<endl
<<left<<setw(7)<<n4<<left<<setw(7)<<n5<<left<<setw(7)<<n6<<endl
<<left<<setw(7)<<n7<<left<<setw(7)<<n8<<left<<setw(7)<<n9;
return 0;
}
/*use of setw() output formator usually it is automatically right
sewidth which are formatted numbers are written on right side spaces are placed at
left this is right justified but adding only word left it will become
left justified we have to only add <<left before <<setw()<<value;
numbers are automatically riht justified but if we want to place right word just like
<<right before stw()<<value */
/*in order to make following program right justified just remove <<left from syntax */
#include <iostream>
using namespace std;
#include <iomanip>
int main()
{
int n1=3,n2=4,n3=435,n4=2453,n5=4535,
n6=43232,n7=231534,n8=25434,n9=2423;
cout<<left<<setw(7)<<n1<<left<<setw(7)<<n2<<left<<setw(7)<<n3<<endl
<<left<<setw(7)<<n4<<left<<setw(7)<<n5<<left<<setw(7)<<n6<<endl
<<left<<setw(7)<<n7<<left<<setw(7)<<n8<<left<<setw(7)<<n9;
return 0;
}
Tuesday, November 25, 2014
c++ program to find factorial of any positive number;
c++ program to find factorial of any positive number;
/*This is a c++ program to find factorial of any number given by user.
we use while loop in it.
store 1 in fact then store fact*i=1*1 in it
when i will come after inrement 2 will store in it
when i will 3 and come ,2 is stored stored in fact now 2*3= 6 will store in it
It will going on till i becomes equal to num*/
#include <iostream> //library
using namespace std;
int main() //tell about main function the execution will start from here
{
int i=1,num; //we declare num and inizialize the count i.e i
double fact=1; //we also start fact from 1
cout<<"Enter number = "; //display message on console
cin>>num; //input number
if (num>0) //applying if so that number should be positive
{
while (i<=num) //applying condion that number should equal to or greater than i
{
fact=fact*i; //now store the product value of fact*i in fact
i++;
}
cout<<"The Factorial = "<<fact<<endl; //we should use {} braces to enclose the body of if,else if,else ;
} //loop and condition in parenthesis ()
else if (num==0) //we can use if separatly but no else if,else
{
cout<<"The factorial = 1"<<endl;
}
else if (num<0)
{
cout<<"Please enter positive number.\n";
}
return 0;
}
/*This is a c++ program to find factorial of any number given by user.
we use while loop in it.
store 1 in fact then store fact*i=1*1 in it
when i will come after inrement 2 will store in it
when i will 3 and come ,2 is stored stored in fact now 2*3= 6 will store in it
It will going on till i becomes equal to num*/
#include <iostream> //library
using namespace std;
int main() //tell about main function the execution will start from here
{
int i=1,num; //we declare num and inizialize the count i.e i
double fact=1; //we also start fact from 1
cout<<"Enter number = "; //display message on console
cin>>num; //input number
if (num>0) //applying if so that number should be positive
{
while (i<=num) //applying condion that number should equal to or greater than i
{
fact=fact*i; //now store the product value of fact*i in fact
i++;
}
cout<<"The Factorial = "<<fact<<endl; //we should use {} braces to enclose the body of if,else if,else ;
} //loop and condition in parenthesis ()
else if (num==0) //we can use if separatly but no else if,else
{
cout<<"The factorial = 1"<<endl;
}
else if (num<0)
{
cout<<"Please enter positive number.\n";
}
return 0;
}
Thursday, November 20, 2014
The c++ program to find the size of data types and then tell also about the data type
Q1) suppose you are programmer but you
have no user manual to see the size of different data types like int, double ,
float , char and long. Write a programm
that will calculate the size of this data types and display data type on
screen.
using namespace std;
int main()
{
int in,size_in;
float fl,size_fl;
double db,size_db;
long lg,size_lg;
short sh,size_sh;
cout<<"Enter int = ";
cin>>in;
size_in=sizeof (in);
cout<<"The size of int(data type) = "<<size_in<<endl<<"Data type is int. "<<endl<<endl;
cout<<"Enter float = ";
cin>>fl;
size_fl=sizeof (fl);
cout<<"The size of float(data type) = "<<size_fl<<endl<<"Data type is float. "<<endl<<endl;
cout<<"Enter double = ";
cin>>db;
size_db=sizeof (db);
cout<<"The size of double(data type) = "<<db<<endl<<"Data type is double."<<endl<<endl;
cout<<"Enter long = ";
cin>>lg;
size_lg=sizeof (lg);
cout<<"The size of long(data type) = "<<size_lg<<endl<<"Data type is long."<<endl<<endl;
cout<<"Enter short = ";
cin>>sh;
size_sh=sizeof (sh);
cout<<"The size of short(data type) = "<<size_sh<<endl<<"Data type is short"<<endl<<endl;
return 0;
}
c++ program to find size of data type int
#include <iostream>
using namespace std;
int main()
{
int in,size;
size=sizeof (in);
cout<<"size ="<<size;
return 0;
}
Q8) A car holds 12 gallons and can
travel 350 miles before refueling. Write a program that calculates the number
of miles per gallon the car gets. Display the result on the screen.
Hint: use the following formula to
calculate miles per gallon (MPG)
MPG = Miles Driven / Gallon of Gas
Used.
#include <iostream>
using namespace std;
int main()
{
int gallons,miles;
double mpg;
gallons=12;
miles=350;
mpg=miles/gallons;
cout<<"MPG = "<<mpg<<endl;
return 0;
}
using namespace std;
int main()
{
int gallons,miles;
double mpg;
gallons=12;
miles=350;
mpg=miles/gallons;
cout<<"MPG = "<<mpg<<endl;
return 0;
}
Q5) Write a program that displays the
following pieces of information, each on separate line:
Your name
Your Degree
Your section
Your Department
Your university
Use single cout statement to do
this.
#include <iostream>
using namespace std;
int main()
{
cout<<"Your Name \n"<<"Your Degree \n"<<"Your Section \n"<<"Your Department \n"<<"Your University \n";
return 0;
}
using namespace std;
int main()
{
cout<<"Your Name \n"<<"Your Degree \n"<<"Your Section \n"<<"Your Department \n"<<"Your University \n";
return 0;
}
Q10) Modify the program of first
question by taking the speed and time from the user as input.
#include <iostream>
using namespace std;
int main()
{
float speed,distance,time;
cout<<"Enter speed = ";
cin>>speed;
cout<<"Enter time = ";
cin>>time;
distance=time*speed;
cout<<"The distance = "<<distance<<endl;
return 0;
}
using namespace std;
int main()
{
float speed,distance,time;
cout<<"Enter speed = ";
cin>>speed;
cout<<"Enter time = ";
cin>>time;
distance=time*speed;
cout<<"The distance = "<<distance<<endl;
return 0;
}
Wednesday, November 19, 2014
Q4) Write a program that stores the
following values in five different variable 28, 32.37,24 and 33. The program
should calculate the sum of these variables and store the result in separate
variable named sum. Then program should divide sum variable by 5 to get the
average. Display average on screen.
#include <iostream>
using namespace std;
int main()
{
int a,b,c,d,e,sum;
double avg;
a=28;
b=32;
c=35;
d=24;
e=33;
{
sum=a+b+c+d+e;
}
{
avg=sum/5;
}
cout<<"Average of five numbers = "<<avg<<endl;
return 0;
}
Q3) Write a
program that computes the tax and tip on a restaurant bill for a patron with a
$44.75 meal charge. The tax should be 6.75 percent of the meal cost. The tip
should be 15 percent of the total after adding the tax. Display the meal cost,
tax amount, tip amount and total bill on the screen.
#include <iostream>
using namespace std;
int main()
{
double meal_cost,tax,new_bill,tip,total_bill;
meal_cost=44.75;
cout<<"Meal cost = "<<meal_cost<<endl;
{
tax=6.75/100*44.75;
}
cout<<"tax = "<<tax<<endl;
{
new_bill = meal_cost + tax;
}
{
tip = (new_bill/100)*15;
}
cout<<"tip = "<<tip<<endl;
{
total_bill= tax + meal_cost + tip;
}
cout<<"total bill = "<<total_bill<<endl;
return 0;
}
C++ program for the division of sum of square of two numbers to square of another number
C++ program for the division of sum of square of two numbers to square of another number
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
float x,y,z;
double div;
cout<<"enter x = \n";
cin>>x;
cout<<"Enter y = \n";
cin>>y;
cout<<"Enter z = \n";
cin>>z;
{
x=pow(x,2);
y=pow(y,2);
z=pow(z,2);
}
{
div=(x+y)/z;
}
cout<<"The division of sum of square of two numbers to square of another number = "<<div;
return 0;
}
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
float x,y,z;
double div;
cout<<"enter x = \n";
cin>>x;
cout<<"Enter y = \n";
cin>>y;
cout<<"Enter z = \n";
cin>>z;
{
x=pow(x,2);
y=pow(y,2);
z=pow(z,2);
}
{
div=(x+y)/z;
}
cout<<"The division of sum of square of two numbers to square of another number = "<<div;
return 0;
}
c++ program to find slope of a graph:
#include <iostream>using namespace std;
int main()
{
float x1,x2,y1,y2;
double slope;
cout<<" Enter value of x1 = \n";
cin>>x1;
cout<<"Enter value of x2 = \n";
cin>>x2;
cout<<"Enter value of y1 = \n";
cin>>y1;
cout<<"Enter value of y2 = \n";
cin>>y2;
{
slope=(y2-y1)/(x2-x1);
cout<<"The slope is = "<<slope;
}
return 0;
}
Tuesday, November 4, 2014
Block a Website on Your PC
1. Open Windows Explorer and navigate to C:\Windows\System32\drivers\etc. If Windows is not installed on C:, substitute the appropriate drive letter.2. Double-click hosts, and select Notepad when Windows prompts you to choose a program. If you don't get the prompt, or if the hosts file opens in another program, open Notepad (Start, All Programs, Accessories, Notepad), and then navigate to hosts by clicking File, Open within Notepad.
3. Place the cursor at the end of the last line, which will say something such as '127.0.0.1 localhost' or '::1 localhost'. Press Enter to create a new line.
4. Type 127.0.0.1, tap the spacebar once, and then type the address of a website you want to block. For example, to block all traffic from YouTube, type 127.0.0.1 www.youtube.com on this line.
5. Continue to add the websites you wish to block, each prefaced with 127.0.0.1 and a space.
6. Click File, Save to commit to your changes. Dismiss any warnings from antimalware software, which may be triggered by your editing of the hosts file.
7. Close any open browser windows, and then reopen a browser to test your edits. The blocked sites should not display in any browser.
Subscribe to:
Posts (Atom)