marți, 11 decembrie 2018

c++ programming part 19

Reduceri de la 800 lei la 600 lei, plata in rate
Rel. la 0729 131 325

1625. Programming interviews
1626. char sel;
1627. sel = "b";
1628. What is wrong?
1629. Answer:
1630. "b" means a string, and sel is a char.
1631. What is the difference between a variable and a literal?
1632. Answer:

1633. Variables represent storage locations in memory, where as literals are constant
values assigned to variables.
1634. What would be the output of the following program?
1635. #include 
1636. using namespace std;
1637. int main()
1638. {
1639. char letter;
1640. letter = 65;
1641. cout << letter << endl;
1642. return 0;
1643. }
1644. Answer:
1645. A
1646. What would be the output of the following program?
1647. #include 
1648. using namespace std;
1649. int main()
1650. {

1651. int i;
1652. float f;
1653. f = 6.9;
1654. i = f;
1655. cout << i << endl;
1656. return 0;
1657. }
1658. Answer:
1659. 8, when a floating point value is truncated, it is not rounded.
1660. Give an example of a loop, who is executing one times.
1661. Give an example of a loop, who is not executing.
1662. Guess the number
1663. Random number
1664. Matematically speaking, they are computer-generated numbers, nor can I as a
progammer control them.
1665. The numbers have two forms:
1666. - scientific form, e.g. 12.34
1667. - exponential form, e.g. 2E3, means 2 multiplied by 10 at power 3=2 x 1000= 2000
1668. The computer must generate a random numeber. Let's generate and see the
number. The function in C++ with wich we generate random number is function
"rand". They are functions defined by the programmer, and predefined functions,
means existing in the language. To use them, it's enough to write their name.
1669. Let's start
1670. #include  
1671.
1672. using namespace std;
1673. int main()
1674. {
1675. double nrc=rand();
1676. //generate number and put them in a variable called nrc
1677. cout<1678. //display the number and pass to the next line
1679. }
1680. To obtain different numbers for each execution, is a must to called first of all,
function random().

1681. So:
1682. #include  
1683. using namespace std;
1684. int main()
1685. {
1686. double nrc=rand();
1687. //generate number and put them in a variable called nrc
1688. cout<1689. //display the number and pass to the next line
1690. }
1691. The player introduce a number.
1692. #include  
1693. using namespace std;
1694.
1695. int main()
1696. {
1697. int nrc=rand();
1698. //declare nrc, generate number and put them in a variable called nrc
1699. cout<1700. //display the number and pass to the next line
1701. //declare nrj and put them in a variable called nrc
1702. int nrj;
1703. cin>>nrj;
1704. //read the input, and put them in a variable called nrj
1705. //compare then the two numbers
1706. if(nrc==nrj)
1707. cout<<"you win";
1708. else
1709. cout<<"you lost";
1710. }
1711. All of this will happen in a while, because the player is most likely not to guess
at first.
1712. #include  
1713. using namespace std;
1714. int main()
1715. {
1716. double nrc=rand();
1717. //generate number and put them in a variable called nrc
1718. cout<1719. //display the number and pass to the next line
1720. int nrj;
1721. //consider a variable guess, initial equal with 0, mean's false.

1722. int ghicit=0;
1723. while(nri!=nrj)
1724. {
1725. cin>>nrj;
1726. //read the input, and put them in a variable called nrj
1727. //compare then the two numbers
1728.
1729. if(nrc==nrj)
1730. {
1731. cout<<"you win";
1732. ghicit=1;//stop game, ghicit has became !=0
1733. }
1734. else
1735. cout<<"you lost";
1736. }
1737. }


Niciun comentariu:

Trimiteți un comentariu

Rețineți: Numai membrii acestui blog pot posta comentarii.