C/C++ :: Can't Get The Right Square Pattern

Jul 4, 2014

I've been working on this code that should be looking like

1 3 5 3 1
3 5 7 5 3
5 7 9 7 5
3 5 7 5 3
1 3 5 3 1

but mine appears like this

1 3 5 3 1
3 5 7 5 3
5 7 9 7 5
3 3 5 7 9
1 3 1 3 5

This is the code I've got for now, I just don't know which logic I need to fix

int main(){
int r;
cout << "Rows?" << endl;
cin >> r;
for (int i = 1; i <= r; i+=2){
for (int j = i; j <= r+i; j+=2){
cout << j<< " ";
} for (int k = i+2; k >= i-1; k-=2){

[code]....

View 2 Replies


ADVERTISEMENT

C++ :: Draw A Square Within A Square Pattern

Oct 25, 2013

I know how to draw a square hollow or filled but i need to draw an alternating pattern ....

ex
iPatternHeight = 1
X

iPatternHeight = 3
OOO
OXO
OOO

[Code] .....

View 6 Replies View Related

C/C++ :: Printing Square Pattern Of Asterisks Based On User Input

Dec 15, 2014

I have to make a program that displays a square of asterisks based on the users input. Here is what I have so far.

#include<iostream>
using namespace std;
int main(){
int number;
cout << "Enter a number: ";
cin >> number;
for (int i = 0; i < number; i++){

[Code] ....

But the square needs to be hollow like this. So if the user enters 5 then the following square will be shown.

*****
* *
* *
* *
*****

How to make it do this.

View 11 Replies View Related

C/C++ :: Displaying Filled Square Next To Hollow Square?

Feb 28, 2015

I am able to display a filled and hollow square by themselves, but I can't seem to be able to get them side by side.

So this is my code so far:

[/
#include <iostream>
using namespace std;
int main()

[Code]....

I can get the hollow square to show up, but the first square just shows up as a single line instead of a square. It seems that it ignores the first if statement in the second loop. I've tried not using an if statement in the second loop but it didn't seem to work either.

View 4 Replies View Related

C# :: How To Draw A Square Within A Square

Oct 25, 2013

I know how to draw a square hollow or filled but I need to draw an alternating pattern

ex
iPatternHeight = 1
X

iPatternHeight = 3
OOO
OXO
OOO

[Code] ......

View 2 Replies View Related

C++ :: Display A Pattern Using Loops

Oct 17, 2014

I have spent at least an hour trying to display this pattern and I am not getting anywhere.

Pattern C
1
21
321
4321
54321
654321

This is as far as I got
#include <iostream>
#include <iomanip>

[Code]....

View 4 Replies View Related

C/C++ :: Nested For Loop Pattern?

Nov 3, 2014

I'm trying to output a pattern using loops. The pattern is a plus symbol made of 3 rows of 5 x's followed by 3 rows of 15 x's and finally 3 rows of 5 x's.

I can get the program to output all 9 rows with 5 x's but I don't know how to do the 3 rows of 15 in the middle. I have tried a while loop and also an if statement but nothing seems to work.

#include "stdafx.h"
#include <iostream>
#include <iomanip>

[Code]....

View 8 Replies View Related

C/C++ :: Pattern Recognition For Numbers?

Jan 3, 2015

i have a .txt file with a bunch of numbers(1...99), millions of them, and i would like to make a program that recognizes patterns(if exists, i don't know) of numbers in this file. What will be the starting point? How could i do that? I read i could do that with Neural Network. Is there other way?

View 11 Replies View Related

C :: Textual Analysis - Pattern Matching

Feb 11, 2014

I am looking to write a program that, given a particular word, looks at a plain text document and gives a list of words that appear within x words of the given word along with a count of how many times it appears.

Do I need to use regex to do the pattern matching here? Is there a particular data structure that I should use that is particularly suited to a task like this? I don't want to reinvent the wheel, it seems like there should be libraries that would already do this sort of thing but searches have turned up nothing.

View 5 Replies View Related

C++ :: Creating Diagonal Pattern By Given Function

Nov 5, 2013

How to create a diagonal pattern by the given function

void diagonal(int size, char op)

The function takes in 2 arguments, size and op and displays a diagonal line of op char. for example, diagonal (5,#) will produce the following output.

#
#
#
#
#

View 4 Replies View Related

C++ :: Printing Even And Odd Numbers In Alternating Pattern?

Nov 23, 2014

We never really had a thorough discussion yet about if-else statements and while.. but our teacher already gave us a difficult assignment..

We should write a program the accepts a number , n, and displays the first n values of the number series:

the pattern to be print was like this 1 1 2 3 4 5 8 7 16 9 32 11 64 13...

alternating odd and even numbers using while and if-else statements

if you input n, the output will print only until 1 1 2 3 4 5 8 7

View 2 Replies View Related

C++ :: Selecting Design Pattern For Validation

Jan 21, 2015

I am looking into some design pattern which works for validation.

I thought about using strategy but not sure whether its correct or not

View 3 Replies View Related

C++ :: Design Pattern For Function Operation

Dec 11, 2014

Any design pattern allows to describe operation like the following.

MyFunctionObject f;
//Init f...
MyFunctionObject g;
//Init g...
MyFunctionObject h = f(g) + g;

[Code] .....

I'm interested in design pattern which permits to model this kind of structure, if there's of course...

View 7 Replies View Related

C++ :: Way / Pattern To Avoid Copying Data

Apr 19, 2013

I have a class buffer, which holds a std::string as member, and a socket_receive function:

struct buffer {
string data;
buffer() {}
buffer(buffer& b) : data(b.data) {}
};
buffer socket_receive() {
buffer tmp;
tmp.data = "1234";
return tmp;
}

so when I write

buffer b = socket_receive();

there is a copy constructor, and the tmp variable is constructed and destructed, is there anyway to improve the performance?

I tried the new c++11 move(), but seems even worse, I must be doing wrong with move(), but I don't know how.

#include <iostream>
#include <string>
#include <ctime>
using namespace std;
struct buffer {
string data;

[Code] .....

View 4 Replies View Related

C/C++ :: Stopping Case For Asterisk Pattern?

Dec 1, 2014

So, I'm going to write a recursive function for a asterisk pattern but I'm stuck figuring out how to create a stopping case for it, better yet, I'm unable to describe the pattern completely.

*
**
-*
****
--*
--**
---*
********
-----*
-----**
------*
-----****
-------*
-------**
--------*

( - represent white spaces )

What I've been thinking:

* Every odd row has 1 * with 1 incremented white space

* Every "pair" of asterisks equals 8 total (EX. 8 one pair *'s, 4 two pair *'s, 2 four pair *'s)

Unfortunately, that's all I got. how I can represent this as I function. Once I figure out what my stopping case should be, I think I can do the coding on my own.

View 1 Replies View Related

C# :: Unit Of Work And Repository Pattern

Oct 18, 2014

I have implemented the IRepository and UnitOfWork Patterns in my project and I have made a little tweak in the UnitOfWork pattern .

public class UnitOfWork : IDisposable {
private DataContext m_Context = new DataContext();
private bool m_disposed = false;

#region Repositories
private GenericRepository<Product> m_ProductRepository = null;
private List<object> m_RepositoryList = new List<object>();
#endregion

[Code] ....

In my UOW class I have the public property ProductRepository. Now my idea was instead of creating a public property for every repository that I have, I created the generic method GetRepository<T> to dynamically create repositories.

Do you think that this change will have bad side effects. I think that it will improve the maintainability of the code.

View 1 Replies View Related

C/C++ :: Can Use Strtok For Splitting A String With A Certain Pattern

Oct 31, 2012

I have a string like "THIS::IS::THE:EXAMPLE::STRING"

I want to split the string to tokens based on "::".

The tokens should be:

THIS
IS
THE:EXAMPLE
EXAMPLE
STRING

View 1 Replies View Related

C++ :: Nested Looping To Create A Pattern

Jul 15, 2012

I am working on some coursework for university at the moment, and one of the questions asks me to 'write a function that will generate the following pattern using nested looping techniques.'

Pattern:

- . . . . . . .
. - . . . . . .
. . - . . . . .
. . . - . . . .
. . . . - . . .
. . . . . - . .
. . . . . . - .
. . . . . . . -

So far I have the following code, but when I compile it I get a host of different errors.

#include <iostream>
int main() {
int A[8][8],i,j;
for(i=0;i<8;i++) {
for(j=0;j<8;j++) {

[Code] ....

How to add code tags on this?

View 13 Replies View Related

C++ :: Singleton Pattern - Delete Pointer Twice

Feb 22, 2012

environment : qt creator 4.7

code:

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
class singleTon {

[Code] ....

this is a singleton pattern first,it doesn't matter, why I could delete this pointer twice?because the gcc compiler?That mean in the surface, "delete pInstance1;" this movement just mark the memory pInstance1 has been deleted but not real?does any one encounter this phenomenon?

View 7 Replies View Related

C :: Print Triangle Pattern Using One Loop And Recursion?

Dec 18, 2013

Q.print triangle pattern using one loop and recursion

eg: 5

Code:

#include <stdio.h>#include <conio.h>
void pattern(int n,int N) {
int i,c=1;

[Code]....

View 8 Replies View Related

C++ :: Design Pattern For Dynamic Function Parameter

Oct 26, 2014

I need to design an interface(a function prototype) that takes an argument which is used to pass information.
The information can be passed by independent modules and third party softwares and hence can vary today and in future.

Basically, the function interface(arg1, info)caters a niche service to many independent applications and needs to process based on requirements passed by applications in the argument(info, in example).

I am looking for a design pattern for the function parameter - info.

Should I use a void pointer that can be casted to respective application specific class in the function ? will this be a good C++ design ?

or should I take this parameter to be a pointer to a generic abstract class that points to the respective application specific specialization ?

Do we have some design pattern to address this so as to handle other unforeseen challenges ?

View 1 Replies View Related

C++ :: Memento Pattern - Snapshot Of Abstract Object?

May 6, 2014

The code below runs correctly (feel free to compile and run it yourself to see what it does). But when I turn Object abstract by uncommenting the line

virtual void foo() = 0;

It obviously won't compile. I want to use a copy constructor rather than restoring one data member at a time because I'm assuming that Object will have many, many data members (and also want to avoid extra responsibility when new data members are added to Object). Of course, using a pointer to Object in Memento will defeat the purpose of taking a snapshot.

#include <iostream>
#include <string>
#include <sstream>
#include <vector>
const std::string NAME = "Object";

[Code] .....

View 9 Replies View Related

C/C++ :: Design Pattern For Extensible Function Parameter

Oct 26, 2014

I need to design an interface(a function prototype) that takes an argument which is used to pass information.

The information can be passed by independent modules and third party softwares and hence can vary today and in future.

Basically, the function interface(arg1, info) caters a niche service to many independent applications and needs to process based on requirements passed by applications in the argument(info, in example).

I am looking for a design pattern for the function parameter - info.

Should I use a void pointer that can be casted to respective application specific class in the function ? will this be a good C++ design ?

or should I take this parameter to be a pointer to a generic abstract class that points to the respective application specific specialization ?

Do we have some design pattern to address this so as to handle other unforeseen challenges ?

View 3 Replies View Related

C# :: Design Pattern For Task Notification System

Feb 24, 2014

I am looking a good design pattern that takes a combination of a Observer Design Pattern and Command Design Pattern.

Observer Design Pattern:

Subject - ISystem
ConcreteSubject - "Different Types of Systems"
Observer - INotifier
ConcreteObserver - "Different Types of Notifier's"

Command Design Pattern: Used to create a task. "Different Types of Task" ....

View 4 Replies View Related

C/C++ :: Program To Print Irregular Star Pattern?

Oct 5, 2014

I am trying to write a program that will make a pattern of stars. The last line is really tripping me up. I have to make the code only using the printf("*"); printf(" "); printf("/n"); statements once. I want to accomplish this with a for loops and if statements.

It is supposed to look like this:

* - 5 spaces before *
* * - 4 spaces before *
* * * - 3 spaces before *
* * * * * * - 0 spaces before *

This is what I've tried so far:

main()
{
int i, j, k;
i=1;
j=1;

[Code]....

here are the links on codepad [URL]

I think my first approach is way off. But I think I am on to something in the second link. I'm trying to print the "*" and extra 2 times on the fourth line. In the second link the compiler appears to be ignoring the || operator. Is my syntax incorrect in the second attempt? How should I change my if statement to make this pattern work?

View 2 Replies View Related

C++ :: Simple Integer Pattern Algorithm - Value Transformation

Mar 19, 2012

In code, I need to transform these values:

256 becomes 0
128 becomes 1
64 becomes 2
32 becomes 3
16 becomes 4
8 becomes 5
4 becomes6

Is there some way to express this mathematically so that I do nto have to use a table lookup? I know this sounds like I am an idiot, but I can not figure out an obvious algorithm.

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved