Giter VIP home page Giter VIP logo

cpp-warmup's Introduction

cpp-warmup

Assignment 0: C++ warm-up. The purpose of this assignment is to familiarize ourselves with C++, cmake, and github.

How to build

Windows

Open git bash to the directory containing this repository.

cpp-warmup $ mkdir build
cpp-warmup $ cd build
cpp-warmup $ cmake -G "Visual Studio 16 2019" ..
cpp-warmup $ make

Then open the solution file to write and test your programs.

macOS

Open terminal to the directory containing this repository.

cpp-warmup $ mkdir build
cpp-warmup $ cd build
cpp-warmup $ cmake ..
cpp-warmup $ make

To run each program from build, you would type

cpp-warmup $ ../bin/fizzbuzz
cpp-warmup $ ../bin/testcircle

Program 1: FizzBuzz

In the file fizzbuzz.cpp, implement the program FizzBuzz, described here. In case you might not be familiar with reading and writing data from the console, we've given you the following starter code.

#include <iostream>
using namespace std;

int main(int argc, char** argv)
{
   int X,Y,N;
   cin >> X;
   cin >> Y;
   cin >> N;
   
   // your code here
}

This program will sit and wait until you enter 3 values.

Program 2: Circle class

Write a class, circle, that stores a radius and has the following methods

  • default constructor (radius is set to 0)
  • constructor taking a radius as argument
  • copy constructor
  • assignment operator
  • output stream operator
  • add operator (should add the radii of two circles together)
  • accessor (e.g. getter) for radius
  • mutator (e.g. setter) for radius
  • method for computing and returning the area

Your class should also

  • Split the class into a header and implementation file
  • Define its methods as public, but data (the radius) as private

For example, running the program, testcircle.cpp, should give the following output.

#include <iostream>

#include "circle.h"

int main(int argc, char** argv)
{
   Circle c1; 
   Circle c2(10); 
   Circle c3 = c2;
   Circle c4 = c2 + c2;

   std::cout << "--------- Starting Values ----------\n";
   std::cout << "c1: " << c1 << std::endl;
   std::cout << "c2: " << c2 << std::endl;
   std::cout << "c3: " << c3 << std::endl;
   std::cout << "c4: " << c4 << std::endl;

   float area = c3.computeArea();
   std::cout << "Circle 3 has area: " << area << std::endl;

   c2 = c1;
   c1.setRadius(c3.getRadius() + 2);

   std::cout << "--------- Ending Values ----------\n";
   std::cout << "c1: " << c1 << std::endl;
   std::cout << "c2: " << c2 << std::endl;
   std::cout << "c3: " << c3 << std::endl;
   std::cout << "c4: " << c4 << std::endl;
}

Output

--------- Starting Values ----------
c1: 0
c2: 10
c3: 10
c4: 20
Circle 3 has area: 314.159
--------- Ending Values ----------
c1: 12
c2: 0
c3: 10
c4: 20

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.