Questions
C++ problem 11-2 In this chapter, the class dateType was designed to implement the date in...

C++ problem 11-2

In this chapter, the class dateType was designed to implement the date in a program, but the member function setDate and the constructor do not check whether the date is valid before storing the date in the member variables. Rewrite the definitions of the function setDate and the constructor so that the values for the month, day, and year are checked before storing the date into the member variables. Add a member function, isLeapYear, to check whether a year is a leap year. Moreover, write a test program to test your class.

Input should be format month day year with each separated by a space.

for dateType.h

//dateType.h

#ifndef date_H

#define date_H

class dateType

{

public:

    void setDate(int month, int day, int year);

      int getDay() const;

      int getMonth() const;

    int getYear() const;

    void printDate() const;

    bool isLeapYear();

dateType(int month = 1, int day = 1, int year = 1900);

private:

int dMonth;      

    int dDay;        

    int dYear;       

};

#endif

---------------------------------------

For dateTypeImp.cpp

#include"dateType.h"

class dateType{

   private:

   int month;

   int day;

   int year;

  

    public:

   

   dateType(){

   }

   

   dateType(int month,int day,int year){

       int maxNumberOfDays[]={31,28,31,30,31,30,31,31,30,31,30,31};

       if(month < 1 || month > 12){

           cout<<"Date :"<<month<<"-"<<day<<"-"<<year;

           cout<<" Month is not valid"<<endl;

       }

       if(day >= 1 && day <= maxNumberOfDays[month]){

       }

       

       else if(month == 2 && day == 29){

           if(isLeapYear() == 1){

              

           }

           else{

               cout<<"Date :"<<month<<"-"<<day<<"-"<<year;

               cout<<" Day is not valid for this month"<<endl;

           }

       }

       else{

           cout<<"Date :"<<month<<"-"<<day<<"-"<<year;

           cout<<" Day is not valid for this month"<<endl;

       }

       if(year < 0){

           cout<<"Date :"<<month<<"-"<<day<<"-"<<year;

           cout<<" year is not valid"<<endl;

       }

       this->month = month;

       this->day = day;

       this->year = year;

   }

   int isLeapYear(){

       int year = this->year;

       

       if((year % 400) == 0){

           return 1;

       }

      

      

       else if((year % 100) == 0){

           return 0;

       }

       else if((year%4) == 0)

           return 1;

       // else

       return 0;

   }

   void setDate(int month,int day,int year){

       

       int maxNumberOfDays[]={31,28,31,30,31,30,31,31,30,31,30,31};

      

       

       if(month < 1 || month > 12){

           cout<<"Date :"<<month<<"-"<<day<<"-"<<year;

           cout<<" Month is not valid"<<endl;

       }

       

       if(day >= 1 && day <= maxNumberOfDays[month]){

       }

       

       else if(month == 2 && day == 29){

           if(isLeapYear() == 1){

               

           }

           else{

               cout<<"Date :"<<month<<"-"<<day<<"-"<<year;

               cout<<" Day is not valid for this month"<<endl;

           }

       }

       else{

           cout<<"Date :"<<month<<"-"<<day<<"-"<<year;

           cout<<" Day is not valid for month="<<month<<endl;

       }

       if(year < 0){

           cout<<"Date :"<<month<<"-"<<day<<"-"<<year;

           cout<<" year is not valid"<<endl;

       }

       this->month = month;

       this->day = day;

       this->year = year;  

   }

   string getDate(){

       return (to_string(this->month)+"-"+to_string(this->day)+"-"+to_string(this->year));

   }

};

--------------------------------------------------------

for main.cpp

#include"dateTypeImp.cpp"

int main(){

   int month;

   int day;

   int year;

   cin>>month>>day>>year;

   dateType Date1(month,day,year);

  

   cout<<"Date 1:"<<Date1.getDate();

   int isLeap = Date1.isLeapYear();

   if(isLeap == 1){

       cout<<" this is a Leap Year"<<endl;

   }

   else{

       cout<<" this is not a Leap Year"<<endl;

   }

   cin>>month>>day>>year;

   dateType Date2;

   Date2.setDate(month,day,year);

   cout<<"Date 2:"<<Date2.getDate();

   isLeap = Date2.isLeapYear();

   if(isLeap == 1){

       cout<<" this is a Leap Year"<<endl;

   }

   else{

       cout<<" this is not a Leap Year"<<endl;

   }

   cin>>month>>day>>year;

   dateType Date3(month,day,year);

   cin>>month>>day>>year;

   dateType Date4;

   Date4.setDate(month,day,year);

  

   cin>>month>>day>>year;

   dateType Date5(month,day,year);

  

   return 0;

}

In: Computer Science

Code in C ++ that asks the user for an integer and that prints whether or...

Code in C ++ that asks the user for an integer and that prints whether or not the number is divisible by three in the integers. If the number is not divisible by three, the program must write a message indicating what the remainder is obtained by dividing the number by three.

In: Computer Science

How is this method coded in Java?

How is this method coded in Java?

In: Computer Science

(Python) This is my code for printing a roster for a team. When I print to...

(Python) This is my code for printing a roster for a team. When I print to the console, it makes the first player's name show up as number 2, and it says [] (its just blank for 1). How can I fix that so the first player's name is 1, not skipping 1 and going to 2.

def file_to_dictionary(rosterFile):

myDictionary={}

myDict=[]

  

with open(rosterFile,'r') as f:

for line in f:

  

(num,first,last,position)=line.split()

myDictionary[num]= myDict

myDict=[first, last, position]

print (myDictionary)

return myDictionary

  

file_to_dictionary((f"../data/playerRoster.txt"))

  

In: Computer Science

SNOWMOBILE CLUB - Database Development Draw an Entity-Relationship Diagram which must include all entities and their...

SNOWMOBILE CLUB - Database Development

Draw an Entity-Relationship Diagram which must include all entities and their attributes. Primary Keys underlined, Foreign Keys labeled, Weak entities double boxed.

You have been asked to develop a database to help the Wisconsin Snowmobile Association track their club members.

The following are the predefined business rules:

1) Snowmobile Clubs are tracked by Wisconsin county.

2) A club can be assigned to multiple counties.

3) Members can belong to one or more clubs.

4) Some clubs could have the same name.

5) New clubs can be started at any time.

6) The Wisconsin Snowmobile Association has an elected Executive Board consisting of a President, Vice President, Secretary, Treasurer and Executive Director, all of whom must be current members.

7) Each county must have a Director and a Representative.

8) Each club has a President, Vice-President, Secretary and Treasurer.

In: Computer Science

Create design document for a program that will allow the user: Convert a number to binary....

Create design document for a program that will allow the user:

  • Convert a number to binary.
  • Convert from binary to number.
  • Display the hexadecimal representation of a binary number.
  • Given an hexadecimal display its binary representation.
  • Convert a number to IEEE single precision and vice versa.
  • More to come.

PLEASE ADD PSEUDOCODE AND USE C PROGRAMMING

USE FUNCTIONS IF POSSIBLE

In: Computer Science

Convert the following binary number (signed 32-bit floating point IEEE-754) into decimal. 0100 0011 0100 0000...

Convert the following binary number (signed 32-bit floating point IEEE-754) into decimal.
0100 0011 0100 0000 0000 0000 0000 0000

In: Computer Science

How does the use of dialogue in a storytelling game differ from its use in other...

How does the use of dialogue in a storytelling game differ from its use in other forms of fiction?

A)The dialogue of characters in a game is always monotone but is characterized by the actor's voice and inflections in other forms of fiction.

B)The dialogue in a storytelling game is always longer and more complex than in other forms of fiction.

C)The dialogue of characters in a game can change based on the player's actions, whereas it stays the same in other forms of fiction.

D)Only the protagonist and antagonist in a game can handle dialogue whereas any character in other forms of fiction can be given dialogue.

In: Computer Science

JAVA In this PoD you will use an ArrayList to store different pet names (there are...

JAVA

In this PoD you will use an ArrayList to store different pet names (there are no repeats in this list). This PoD can be done in your demo program (where your main method is) – you don’t have to create a separate class for today.

Details

Create an arraylist of Strings, then using a Scanner object you will first read in a number that will tell you how many pet names (one word) you will add to the arraylist.

Once you have added all the names, print the list.

Then read in one more pet name. If this is pet name already exists, do nothing, but if the pet name isn’t in the list, add it to the front of the list (e.g., the first position).

Print the list again.

Next read in two more pet names. If the first pet name is in the list, replace it with the second pet name. If the first pet name isn’t in the list, add the second pet name to the end of the list.

Print the list again.

Input

Example Input:
5 Whiskers Benji Lassie Smokey Bob Triffy Bob Max

Output

Example Output:
[Muffin, Benji, Snowball, Fluffy]
[Muffin, Benji, Snowball, Fluffy]
[Muffin, Benji, Snowball, Whiskers, Fluffy]

In: Computer Science

In Artificial intelligence: 3.3. What are the problems of global searches? Explain.

In Artificial intelligence:

3.3. What are the problems of global searches? Explain.

In: Computer Science

(PYTHON) Write a program that does the following: reads each line from a txt file and...

  1. (PYTHON) Write a program that does the following:
    • reads each line from a txt file and convert it to lowercase
    • counts the number of instances of: the characters 'a', 'e','i','o' and 'u' in the file
    • creates a new file of file type .vowel_profile
    • print outs lines in the file indicating the frequencies of each of these vowels
    • Example input/output files:
      • paragraph_from_wikipedia.txt (sample input) link: https://cs.nyu.edu/courses/fall19/CSCI-UA.0002-007/paragraph_from_wikipedia.txt
      • paragraph_from_wikipedia.vowel_profile (sample output) link: https://cs.nyu.edu/courses/fall19/CSCI-UA.0002-007/paragraph_from_wikipedia.vowel_profile

Please help!

In: Computer Science

Have to use C language Pseudocode A #define called BITS should be set at the top...

Have to use C language
Pseudocode
A #define called BITS should be set at the top of the program. It should be set to 8 when the program is submitted. This
define should be used throughout the entire program when setting/using array sizes/max element. This define will also
be used in the output to print 8-bit vs 16 bit. Your program should function whether the define is set to 8 or to 16.
Part of the grading process will be to change the define from 8 to 16 and to recompile your program to see if your program still
runs properly. See sample output.
main()
Print instructions (see sample output below)
Prompt for and store both numbers and the operator. Use only one scanf() to store all three values.
While either number is less than 0 or more than 255, continue to prompt for input until a valid number is entered (hint
– use a while loop). See sample output below.
Call function ConvertDecimalToBinary() to convert the first number to binary.
Call function ConvertDecimalToBinary() to convert the second number to binary.
If the entered operator is an allowed operator, then convert the result to binary and print the decimal result and
binary result as seen in the sample code.
ConvertDecimalToBinary()
Return type : void
Parameters :
int containing the decimal value to be converted
char array (hint : the array is passed empty from main() and this function fills it so when the function
finishes, the array back in main() will contain the values added in the function).
This function will use a method of decimal to binary conversion called “Divide in Half, Ignore the Remainder”. Please
watch the following video for a demonstration of the method.
https://youtu.be/XdZqk8BXPwg
Create a local int array. This array will store the result of each divide by 2 which will be accomplished using
bitshifting instead of division to divide the number in half. Use a bitmask to determine if an array element if odd (1) or
even (0). YOU MUST USE THIS METHOD IN THIS ASSIGNMENT.
Using a for loop, loop over the int array and write each element into the char array that was passed in. Hint : keep
in mind what the ASCII value is for the number zero when writing the int array element into the char array. If you
store the number 65 in a char, it will be ‘A’ so if you want to store the number 0 in a char array, you will need to …?
HINT : make sure your char arrays are one bigger than the number of BITS so that you have room for the null terminator so
that %s prints correctly.
Bitwise Calculator
Enter two base 10 values with a bitwise operator to see the decimal result
and the binary result. The format is
FirstNumber BitwiseOperator SecondNumber
For example, enter the expression
2 & 3
This calculator can used with &, |, ^, << and >>
Please note that the spaces between numbers and operator is essential
and the two entered values must be between 0 and 255
Enter expression 2 & 3
In base 10...
2 & 3 = 2
In 8-bit base 2...
00000010
&
00000011
========
00000010
--------------------------------------------------------------------------------------
Bitwise Calculator
Enter two base 10 values with a bitwise operator to see the decimal result
and the binary result. The format is
FirstNumber BitwiseOperator SecondNumber
For example, enter the expression
2 & 3
This calculator can used with &, |, ^, << and >>
Please note that the spaces between numbers and operator is essential
and the two entered values must be between 0 and 255
Enter expression 2 | 3
In base 10...
2 | 3 = 3
In 8-bit base 2...
00000010
|
00000011
========
00000011
--------------------------------------------------------------------------------------
Bitwise Calculator
Enter two base 10 values with a bitwise operator to see the decimal result
and the binary result. The format is
FirstNumber BitwiseOperator SecondNumber
For example, enter the expression
2 & 3
This calculator can used with &, |, ^, << and >>
Please note that the spaces between numbers and operator is essential
and the two entered values must be between 0 and 255
Enter expression 2 ^ 3
In base 10...
2 ^ 3 = 1
In 8-bit base 2...
00000010
^
00000011
========
00000001
--------------------------------------------------------------------------------------
Bitwise Calculator
Enter two base 10 values with a bitwise operator to see the decimal result
and the binary result. The format is
FirstNumber BitwiseOperator SecondNumber
For example, enter the expression
2 & 3
This calculator can used with &, |, ^, << and >>
Please note that the spaces between numbers and operator is essential
and the two entered values must be between 0 and 255
Enter expression 2 << 3
In base 10...
2 << 3 = 16
In 8-bit base 2...
00000010 << 3
00010000
--------------------------------------------------------------------------------------
Bitwise Calculator
Enter two base 10 values with a bitwise operator to see the decimal result
and the binary result. The format is
FirstNumber BitwiseOperator SecondNumber
For example, enter the expression
2 & 3
This calculator can used with &, |, ^, << and >>
Please note that the spaces between numbers and operator is essential
and the two entered values must be between 0 and 255
Enter expression 2 >> 3
In base 10...
2 >> 3 = 0
In 8-bit base 2...
00000010 >> 3
00000000
--------------------------------------------------------------------------------------
Bitwise Calculator
Enter two base 10 values with a bitwise operator to see the decimal result
and the binary result. The format is
FirstNumber BitwiseOperator SecondNumber
For example, enter the expression
2 & 3
This calculator can used with &, |, ^, << and >>
Please note that the spaces between numbers and operator is essential
and the two entered values must be between 0 and 255
Enter expression 100 >> 3
In base 10...
100 >> 3 = 12
In 8-bit base 2...
01100100 >> 3
00001100
--------------------------------------------------------------------------------------
Bitwise Calculator
Enter two base 10 values with a bitwise operator to see the decimal result
and the binary result. The format is
FirstNumber BitwiseOperator SecondNumber
For example, enter the expression
2 & 3
This calculator can used with &, |, ^, << and >>
Please note that the spaces between numbers and operator is essential
and the two entered values must be between 0 and 255
Enter expression 2 * 3
Operator * is not supported by this calculator
Change
#define BITS 8
to
#define BITS 16
Bitwise Calculator
Enter two base 10 values with a bitwise operator to see the decimal result
and the binary result. The format is
FirstNumber BitwiseOperator SecondNumber
For example, enter the expression
2 & 3
This calculator can used with &, |, ^, << and >>
Please note that the spaces between numbers and operator is essential
and the two entered values must be between 0 and 255
Enter expression 4 & 6
In base 10...
4 & 6 = 4
In 16-bit base 2...
0000000000000100
&
0000000000000110
========
0000000000000100

If you have questions please ask .. Thank you.

In: Computer Science

In artificial intelligence: 3.4. What are the problems of local searches? Explain.

In artificial intelligence:

3.4. What are the problems of local searches? Explain.

In: Computer Science

I'm generating a random number every 10 second; In arraylist I'm Storing and Updating the number...

I'm generating a random number every 10 second; In arraylist I'm Storing and Updating the number every 10 second when I generate new number. However, my goal to call the update number from arraylist in another class main method. I would apperciate any help.

//this is the class I'm generating a random number every 10 second and Storing and Updating the number in arraylist.

package com.singltondesignpattern;

import java.util.ArrayList;

import java.util.Random;

import java.util.concurrent.Executors;

import java.util.concurrent.ScheduledExecutorService;

import java.util.concurrent.TimeUnit;

public class EverySecond {

public static int genrand() {

Random number =new Random();

int rand=number.nextInt(1000);

return rand;

}

public static void getrand(int rand) {   

ArrayList <Integer> randomstorage = new ArrayList<Integer>();

randomstorage.add(rand);

System.out.println("Array value "+randomstorage);

}

public static void main(String[] args) throws Exception {

Runnable helloRunnable = new Runnable() {

public void run() {

int CurrentNum=genrand(); //create a random number

System.out.println("generate number ==== "+CurrentNum);

getrand(CurrentNum); //update it in array list

}

};

ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);

executor.scheduleAtFixedRate(helloRunnable, 0, 10, TimeUnit.SECONDS);

   }

}

//this is the class I want to get the update number from the arraylist

public class getTheUpdate {

public static void main(String[] args) throws Exception {

EverySecond everySecond = new EverySecond();

everySecond.getrand(0);

}

}

In: Computer Science

1. Why a computer can perform some tasks for us? 2. What computer device could Fetch...

1. Why a computer can perform some tasks for us?

2. What computer device could Fetch instructions, follow the instructions, and produce some results?

3. What is the function of computer memory (RAM)? What is used to translate each source code instruction into the appropriate machine language instruction?

4. What is the correct sequence in the process of translating a source file into an executable file?

5. The step that will uncover any syntax errors in your program is ________________.

6. What is a set of rules that must be followed when constructing a program?

In: Computer Science