#1 - Prime Number List use the isPrime function that you wrote in Programming Ch
ID: 3535397 • Letter: #
Question
#1 - Prime Number List
use the isPrime function that you wrote in Programming Challenge 21 in a program that stores a list of all the prime numbers 1 through 100 in a file.
#2 - Rock, Paper, Scissors game
Write a program that lets the user play the game of rock, paper, scissors against the computer.
The program should work as follows.
1. When the programs begins, a random integer number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. (Dont display the computer's choice yet)
2. The user enters his or her choice of rock, paper, or scissors at the key-board. (You can use a menu if you prefer.)
3. The computer's choice is displayed.
4. A winner is selected according to the following rules L
- If one player chooses rock and the other player chooses scissors, then rock wins. (The rock smashes the scissors)
- If one player chooses scissors and the other player chooses paper, then scissors wins. (scissors cuts paper.)
- If one player chooses paper and the other playerchooses rock, then paper wins. (paper wraps rock.)
- If both players make the same choice, the game must be played again to determine the winner.
Be sure to divide the program into functions that perform each major task.
#3 - Payroll
Write a program that uses the following arrays:
* empId: an array of seven long integers to hold employee identification numbers.
The array should be initialized with the following numbers:
5658845 4520125 7895122 8777541 8451277 1302850 7580489
* hours: an array of seven integers to hold the number of hours worked by each employee
* payRate: an array of seven doubles to hold each employee s hourly pay rate
* wages: an array of seven doubles to hold each employee s gross wages
The program should relate the data in each array through the subscripts. For example, the number in element 0 of the hours array should be the number of hours worked by the employee whose identi cation number is stored in element 0 of the empId array. That same employee s pay rate should be stored in element 0 of the payRate array.
The program should display each employee number and ask the user to enter that employee s hours and pay rate. It should then calculate the gross wages for that employee (hours times pay rate) and store them in the wages array. After the data has been entered for all the employees, the program should display each employee s identification number and gross wages.
Input Validation: Do not accept negative values for hours or numbers less than 6.00 for pay rate.
Explanation / Answer
1)
prime number list....
#include<iostream.h>
#include<fstream.h>
void main()
{
int n,i,a;
fstream file;
file.open("output.dat");
for(i=2;i<100;i++)
{
a=0;
for(int j=1;j<=i;i++)
{
n=i%j;
if{n==0)
{
a++;
}
}
if (a==2)
{
file.write((*ch)&i,sizeof(i));
}
}
cout<<"list of prime number is ";
while(file!=eof)
{
n=file.read((*ch)&n,sizeof(n));
cout<<n<<" ";
}
file.close();
}
2)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.