Jump to content
Hash, Inc. Forums
robcat2075

C++ Study Group... 2020!

Recommended Posts

Here we are starting C++ again!

We will post our between-meeting questions and tips in this thread.

Here is a tip to make all your C++ class projects all live in one place and easy to find. Do it this way to save yourself future headaches.

  1. Run Visual Studio and choose "Continue without code ->"...
    ContinueWithoutCode.jpg

     
  2. When the main screen opens, do File>New>Project...
    FileNewPRoject.jpg


     
  3. On the "Create a new project" screen choose "Console App" and Next...
    CreateANewProject.jpg

     
  4. On the "Configure your new Project" screen
    - enter "00_Start" for Project name
    -for Location, navigate to a folder on your hard drive that that will easy to find.
    -for Solution name, enter a title for this whole class
    - leave "Place solution and project in the same directory" unchecked.
    - press Create
    ConfigureNewProject.jpg


     
  5.  VS will churn for a bit and open up a project titled "00_Start.cpp".  This project is in the "solution" you gave a name to in the previous step.

    From now on, when you run VS for this class you will direct it to open this Solution and all your class projects will be added to this solution, with names that are two digits for the class chapter number, an underscore and a chapter title.

    All your new projects will be accessible in the "Solution Explorer" on the right side of the screen.

    00_StartProject.jpg

     
  6. Click on "> Local Windows Debugger" to compile and run the sample code VS has put in the code window. A console widow should appear like this...

    Console.jpg

     

Share this post


Link to post
Share on other sites

Meeting tonight at 8 CST.

We will just make sure everyone is on board with proper solution/project management and then if we have time we will finish the Pong game by adding... the paddle!

@Rodney @Roger @Shelton

There is still time if anyone else wishes to join in on C++!

PM Me!

Share this post


Link to post
Share on other sites

Reminder... the Chapter 4 assignment is to watch Lecture 4 and then type in John Purcell's "Hello World" program from scratch.

Start a new Console project, delete the sample code that VS gives you and type in your new "Hello World program" on the blank page.

 

Share this post


Link to post
Share on other sites

Chris Daley showed me an option in Visual Studio that may explain difference in results we were getting with simple Console window operation last Saturday.

On the top menu do Tools>Options.

In the Options Window that opens make sure that Debugging>General>Automatically close the Console when debugging stops is unchecked.


image.png

Share this post


Link to post
Share on other sites

I'll note that the Chapter 04 lecture, "Hello World" is the longest video until way out past the 60th chapter when he gets into his particle fire project. They're all shorter after this one!

So... get over the hump!

Watch the lecture, type in your own "Hello World" from scratch and bring it to our meeting on Saturday.

Share this post


Link to post
Share on other sites

Assignment for Chapter 5 "Outputting Text"

You can do anything that demonstrates outputting text. If you can't think of anything, the default assignment is to output three lines of dialog from a movie or TV show of your choice.

Your output will look like this...

 

Quote

 

Fred: Where's my coffee?

Wilma: It's on the table, Fred!

Fred: Where's the table?

 

 

Share this post


Link to post
Share on other sites

Here's how to learn this stuff...

  1. Watch the lecture
  2. Watch the lecture again, but every time John Purcell types something in and runs it, you type it in and run it too.

All of his programs will run without modification in our MS Visual Studio environment, so if yours doesn't... look at his to see what you left out.

       3. Do the assignment.

 

That's how i did it, it worked for me, that's how I got through the course!

 

Share this post


Link to post
Share on other sites

Our meeting at 8:30 tonight is, as usual at the Live Answer Time hangout link.

Share this post


Link to post
Share on other sites

Assignment for Chapter 6

Do anything you want that demonstrates use of variables. if you can't think of anything, do this default assignment...

06 Variables

Write a program that declares and assign values to at least two variables, print out their values with labels and also print out their value added together. There is no user input necessaary for this program, you can just hard-code the values into it.

Example output:

 

 

Quote

 

Apples 5

Pears 3

 

Fruit 8

 

 

 

Share this post


Link to post
Share on other sites

Default projects for our next meeting...

07 Strings - Working with Text

Invent a sentence of three clauses, assign each clause to a string variable and print it out three ways...

  • Print each string variable on a separate line

  • Print all three on one line in one cout statement

  • Concatenate all three into a new string variable and print that one out in a cout statement

Example output:

 

 

Quote

A man,

a plan,

Panama!

 

A man, a plan, Panama!

A man, a plan, Panama!

 

08 User Input

Modify your chapter 06 project to have the user input a name and input the numeric values instead of hard coding them in the program.

Remember to “prompt” inputs and “label” outputs.

Example run of program:

 

Quote

Enter a name: John

 

How many apples does John have? 5

How many pears does John have? 3

 

John has 5 apples, 3 pears and 8 total fruit.

 

Alternate project idea...

A “mad-lib” program that prompts the user for seemingly unrelated words, then combines them with other text in some amusing way.

Share this post


Link to post
Share on other sites

Default projects for chapter 10 and 11

10 Integer types

Pick out four different kinds of integers of the several available types. Use sizeof() to reveal how many bytes each one uses and use the system constants to find their MIN and MAX values in our compiler environment.

As always, label your outputs.

Example output...
 

        Integer Types

Enter  bytes of available RAM: 100

The size of an int is 4 bytes.
25 ints can fit in 100 bytes.
The maximum value of an int is 2147483647
the minimum value of an int is -2147483648

The size of a short int is 2 bytes.
50 short ints can fit in 100 bytes.
The maximum value of a short int is 32767
the minimum value of a short int is -32768

The size of a long int is 4 bytes.
25 long ints can fit in 100 bytes.
The maximum value of a long int is 2147483647
the minimum value of a long int is -2147483648

The size of an unsigned long int is 4 bytes.
25 unsigned long ints can fit in 100 bytes.
The maximum value of an unsigned long int is 4294967295
the minimum value of an unsigned long int is 0

11 Floating Point types

Input or hard code a floating point number into your program and display it back out in default, fixed and scientific notation.

Input or hard code a double floating point number and display it back out with different amounts of "precision"

Extra... show how many bytes a float and double float occupy.

Extra-extra... John Purcell doesn't explain how to turn off fixed and scientific notation. You'll have to look that up!

As always, label your outputs.
 

Example output...

        FLUN with FLOAT

Enter a floating point number: 98.6

Number: 98.6
Number in fixed notation: 98.599998
Number in scientific notation: 9.860000e+01

Enter a double floating point number: 3.14159265358979323846

Number in  5 digits: 3.1416
Number in 10 digits: 3.141592654
Number in 15 digits: 3.14159265358979

 

Share this post


Link to post
Share on other sites

Here are some long numbers that can be used as tests for floating point formatting

 

sq root of 2

1.4142356237309504880168872420969807856967187537694807317667973799

pi

3.141592653589793238462643383279502884197169399375105820974944592307816406286

 

Avogadro's number

602214141070409084099072

Share this post


Link to post
Share on other sites

Default project for Chapter 12 Chars and Bools

Declare a Bool variable.  Set it to False and print out its value. Set it to true and print out its value.

Declare several Char variables.

Prompt the user for value for each one, then print them out as if they made one word.

"Cast" the chars to ints and print out their numeric values

Remember to prompt the inputs and label the outputs

 

sample output

Quote

Bools

bvalue when true: 1
bvalue when false: 0

Chars

Input 1st letter: a
Input 2nd letter: l
Input 3rd letter: b
Input 4th letter: e
Input 5th letter: r
Input 6th letter: t

The chars spell albert
The char numeric values are 97, 108, 98, 101, 114, 116
The chars reversed: trebla

 

Share this post


Link to post
Share on other sites

Chapter 13 and 14 combined default project

13 and 14 are shades of the same IF concept. 13 is IF and ELSE . 14 adds ELSEIF

Write a program that prompts the user to input the number of sides of an A:M patch and then respond apprpriately as to whether that is an allowed number of sides or needs special treatment or isn't allowed at all!
 

How many sides does your patch have? 7

No, 7 sides is not allowed.

 

Or do anything else to demonstrate IF, ELSE and ELSEIF

 

Share this post


Link to post
Share on other sites

Chapter 16  Floats default project

Contrive some pair of calculations that should create the same result but fail the == test because of the inexact nature of floating point numbers.

Then find what the smallest +- range is that they can be compared and pass as approximately equivalent.

Output all with labels.

The various formatting and significant digits options we encountered in Chapter 11 might be useful to dust off for this project.

 

Chapter 17  C++ conditions default project

Prompt the user to input several factors (example: age, weight, ...) and then output some diagnosis based on the combination of those in a C++ condition

For example:

  • to be an Astronaut you have to be over 21 AND under 48" tall AND under 120 lbs.
  • to be a Sumo wrestler you need to be over 18 AND over 60" tall AND over 400 lbs.

 

 

 

Share this post


Link to post
Share on other sites

Another possibility for C++ conditions is a simple card (one round) where you have to get above a certain number but below another number to win.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...